Skip to content

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

FieldTypeRequiredNotes
modelstringyesAny model id from the Models page.
messagesMessage[]yesOpenAI message format. Each message has role and content.
streambooleannoSet to true for SSE. See Streaming.
temperaturenumber (0–2)noDefault 1.
max_tokensintegernoCap on output tokens.
top_pnumber (0–1)noNucleus sampling.
toolsTool[]noOpenAI tool/function calling format. Routed to the provider's equivalent.
stopstring | string[]noStop sequences. Up to 4.
userstringnoEnd-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_reason values are normalized across providers: stop, length, tool_calls, content_filter.
  • See Error Codes for failure handling.