Back to Home

Chat Completions

OpenAI-compatible chat completions endpoint. Every model that supports the chat format (GPT, Claude, Gemini, etc.) goes through this route.

Request

POST /v1/chat/completions

Body

FieldTypeRequiredDescription
modelstringModel ID, e.g. gpt-5.5, claude-sonnet-4-6
messagesarrayConversation history. Each item has role and content
streambooleanStream the response. Default false
temperaturenumber0-2. Higher = more creative
max_tokensintegerMaximum output tokens
toolsarrayFunction calling tool definitions

Example

curl https://api.tokensmart.ai/v1/chat/completions \
  -H "Authorization: Bearer pk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.5",
    "messages": [
      { "role": "system", "content": "You are a friendly assistant" },
      { "role": "user", "content": "What is the weather in Beijing today?" }
    ],
    "temperature": 0.7
  }'

Response

{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "model": "gpt-5.5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "I cannot fetch real-time weather..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 42,
    "total_tokens": 67
  }
}

Streaming

Pass "stream": true and the response turns into SSE format. Each chunk is a JSON delta.

See the OpenAI Chat Completions reference for full details.