Skip to Content
WikiAPI DocumentationChat Completions

Chat completions

Creates a model response for the given chat conversation.

Endpoint

POST https://gateway.mytokengate.com/v1/chat/completions

Request Example

curl --request POST \ --url https://gateway.mytokengate.com/v1/chat/completions \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "model": "gpt-4o", "messages": [ { "role": "user", "content": "What opportunities and challenges will the Chinese large model industry face in 2025?" } ] }'

Authentication

All requests require a Bearer token in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Request Parameters

ParameterTypeRequiredDescription
modelstringYesModel name. See Models for available options.
messagesarrayYesA list of messages comprising the conversation so far.
max_tokensintegerNoMaximum tokens to generate. Ensure input + output tokens don’t exceed model’s context window.
streambooleanNoIf true, returns tokens as Server-Sent Events. Stream terminates with data: [DONE].
temperaturefloatNoControls randomness. Range: 0-2. Default varies by model.
top_pfloatNoNucleus sampling parameter. Default: 0.7
top_kfloatNoTop-k sampling parameter.
frequency_penaltyfloatNoPenalizes repeated tokens. Range: -2.0 to 2.0.
stopstring or arrayNoUp to 4 sequences where generation will stop.
nintegerNoNumber of completions to generate. Default: 1
response_formatobjectNoSpecifies output format (e.g., { "type": "json_object" }).
toolsarrayNoList of tools the model may call. Max 128 functions.

Response

{ "id": "chatcmpl-xxx", "choices": [ { "message": { "role": "assistant", "content": "The response text...", "tool_calls": [ { "id": "call_xxx", "type": "function", "function": { "name": "function_name", "arguments": "{\"arg\": \"value\"}" } } ] }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 123, "completion_tokens": 456, "total_tokens": 579 }, "created": 1234567890, "model": "gpt-4o", "object": "chat.completion" }

Error Codes

CodeDescription
400Invalid request parameters
401Invalid or missing API key
404Model not found
429Rate limit exceeded
503/504Service temporarily unavailable
Last updated on