Chat Completions
POST /v1/chat/completions (API credit) or /token/v1/chat/completions (API token)
Generate a model response from a list of messages. This is the primary endpoint and the one OpenAI SDKs are designed for.
Set the OpenAI-compatible base URL to https://api.yourdomain.example/v1 for API credit or https://api.yourdomain.example/token/v1 for an API-token key. For native Claude clients, use the Anthropic Messages origin described in the Claude Code and Claude Desktop guides instead.
Request body
| Field | Type | Required | Notes |
|---|---|---|---|
model | string | yes | Any model id from the Models page. |
messages | Message[] | yes | OpenAI message format. Each message has role and content. |
stream | boolean | no | Set to true for SSE. See Streaming. |
temperature | number (0–2) | no | Default 1. |
max_tokens | integer | no | Cap on output tokens. |
top_p | number (0–1) | no | Nucleus sampling. |
tools | Tool[] | no | OpenAI tool/function calling format. Routed to the provider's equivalent. |
stop | string | string[] | no | Stop sequences. Up to 4. |
user | string | no | End-user identifier for abuse detection. |
Example request
request.sh
curl "$CLOUDSERVICE_BASE_URL/chat/completions" \
-H "Authorization: Bearer $CLOUDSERVICE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_AUTHENTICATED_MODEL_ID",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0.2,
"max_tokens": 100
}'Example response
response.json
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1719228000,
"model": "fable-5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 3,
"total_tokens": 31
}
}Tool use
Function calling follows OpenAI's tool/function format. When a model returns a tool_calls entry, append the result as a role: "tool" message and send again.
tool-call response
{
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [{
"id": "call_...",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Paris\"}"
}
}]
},
"finish_reason": "tool_calls"
}]
}Notes
- Prompt caching is supported where the upstream provider supports it. Customer API-credit billing still charges cached input once at the published input rate; any provider cache discount is an internal cost and is not a customer discount.
finish_reasonvalues are normalized across providers:stop,length,tool_calls,content_filter.- See Error Codes for failure handling.