Chat Completions
Chat Completions
Creates a model response for the given chat conversation.
Endpoint
POST /v1/chat/completionsRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | No | Model ID (defaults to gemma-4-26b) |
messages | array | Yes | Array of message objects |
stream | boolean | No | Enable SSE streaming (default: false) |
temperature | number | No | Sampling temperature (0-2, default: 1) |
max_tokens | integer | No | Maximum tokens to generate (1-128000) |
top_p | number | No | Nucleus sampling (0-1, default: 1) |
frequency_penalty | number | No | Frequency penalty (-2 to 2) |
presence_penalty | number | No | Presence penalty (-2 to 2) |
stop | string/array | No | Stop sequences |
n | integer | No | Number of completions (1-128) |
tools | array | No | Function/tool definitions |
tool_choice | string/object | No | Tool selection strategy |
Message Object
| Field | Type | Required | Description |
|---|---|---|---|
role | string | Yes | system, user, assistant, or tool |
content | string | Yes | Message content |
tool_call_id | string | No | Required for role: "tool" |
tool_calls | array | No | Tool calls made by assistant |
Example
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
| Status | Type | Description |
|---|---|---|
| 401 | authentication_error | Invalid or missing API key |
| 400 | invalid_request_error | Invalid request parameters |
| 429 | rate_limit_error | Rate limit exceeded |
| 502 | upstream_error | Model service unavailable |