Overview
The chat completions endpoint allows you to interact with CTGT AI models to generate responses based on conversation history.
Endpoint: https://api.ctgt.ai/v1/chat/completions
Method: POST
Authentication
All requests require a Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEY
Request Parameters
Parameter Type Required Description modelstring Yes The model to use (e.g., gemini-2.5-flash-lite) messagesarray Yes Array of message objects with role and content personastring No The persona to use (default: "default") streamboolean No Whether to stream the response (default: false) max_tokensinteger No Maximum tokens to generate userstring No Unique identifier for the end-user
Available Personas
Choose from the following personas to customize the model’s behavior:
default - Standard balanced responses
technical_expert - Detailed technical explanations
creative_writer - Creative and engaging content
educator - Clear, teaching-oriented responses
safety_first - Extra emphasis on safety and caution
insurance_underwriter - Risk assessment and insurance analysis
financial_analyst - Financial analysis and investment insights
Code Examples
Python (requests)
Python (OpenAI SDK)
JavaScript (fetch)
cURL
import requests
import json
url = "https://api.ctgt.ai/v1/chat/completions"
api_key = "YOUR_API_KEY"
headers = {
"Authorization" : f "Bearer { api_key } " ,
"Content-Type" : "application/json"
}
payload = {
"model" : "gemini-2.5-flash-lite" ,
"persona" : "default" ,
"messages" : [
{
"role" : "user" ,
"content" : "Why is the sky blue?"
}
],
"stream" : False ,
"user" : "user-123" ,
}
try :
response = requests.post(url, headers = headers, json = payload)
response.raise_for_status()
print (json.dumps(response.json(), indent = 2 ))
except Exception as e:
print ( f "Error: { e } " )
A successful response returns a JSON object with the following structure:
{
"id" : "chatcmpl-123" ,
"object" : "chat.completion" ,
"created" : 1677652288 ,
"model" : "gemini-2.5-flash-lite" ,
"choices" : [
{
"index" : 0 ,
"message" : {
"role" : "assistant" ,
"content" : "The sky appears blue due to a phenomenon..."
},
"finish_reason" : "stop"
}
],
"usage" : {
"prompt_tokens" : 9 ,
"completion_tokens" : 12 ,
"total_tokens" : 21
}
}
Error Handling
The API returns standard HTTP status codes:
200 : Successful request
400 : Bad request (invalid parameters)
401 : Unauthorized (invalid API key)
429 : Rate limit exceeded
500 : Internal server error
Example error response:
{
"error" : {
"message" : "Invalid API key provided" ,
"type" : "invalid_request_error" ,
"code" : "invalid_api_key"
}
}
Best Practices
Pro tip: Use the [persona] parameter to tailor responses to your specific use case without changing your prompts.
Always keep your API key secure and never expose it in client-side code. Use environment variables or secure key management systems.
Use appropriate personas to tailor responses to your use case
Implement proper error handling for production applications
Consider using streaming for better user experience with long responses
Monitor your API usage and rate limits regularly