Skip to content

Chat Completions

Chat Completions

Creates a model response for the given chat conversation.

Endpoint

POST /v1/chat/completions

Request Body

ParameterTypeRequiredDescription
modelstringNoModel ID (defaults to gemma-4-26b)
messagesarrayYesArray of message objects
streambooleanNoEnable SSE streaming (default: false)
temperaturenumberNoSampling temperature (0-2, default: 1)
max_tokensintegerNoMaximum tokens to generate (1-128000)
top_pnumberNoNucleus sampling (0-1, default: 1)
frequency_penaltynumberNoFrequency penalty (-2 to 2)
presence_penaltynumberNoPresence penalty (-2 to 2)
stopstring/arrayNoStop sequences
nintegerNoNumber of completions (1-128)
toolsarrayNoFunction/tool definitions
tool_choicestring/objectNoTool selection strategy

Message Object

FieldTypeRequiredDescription
rolestringYessystem, user, assistant, or tool
contentstringYesMessage content
tool_call_idstringNoRequired for role: "tool"
tool_callsarrayNoTool calls made by assistant

Example

Terminal window
curl -X POST https://cryptgpt.co/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemma-4-26b",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0.7,
"max_tokens": 1024
}'

Response

{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1718169600,
"model": "gemma-4-26b",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 8,
"total_tokens": 33
}
}

Streaming

Set stream: true to receive Server-Sent Events (SSE):

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":"The"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":" capital"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{},"finish_reason":"stop"}]}
data: [DONE]

Function Calling

Pass tools in the request to enable function calling:

{
"model": "gemma-4-26b",
"messages": [{"role": "user", "content": "What's the weather in London?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
}
}
]
}

Error Responses

StatusTypeDescription
401authentication_errorInvalid or missing API key
400invalid_request_errorInvalid request parameters
429rate_limit_errorRate limit exceeded
502upstream_errorModel service unavailable