Skip to main content
The /v1/chat/completions endpoint is the primary way to generate text and hold multi-turn conversations with any model available through TokModel. Because it follows the OpenAI Chat Completions API shape, you can drop TokModel into any existing OpenAI client by changing only the base_url — no other code changes required.

Authentication

Every request must include your API key in the Authorization header:
You can create and manage API keys in the TokModel console.

Send a basic request

The minimum required fields are model and messages. The messages array holds an ordered conversation history, where each entry has a role (system, user, or assistant) and a content string.

Example response

A successful request returns a JSON object. The generated text is in choices[0].message.content.

Use a system message

A system message sets the behavior and context for the assistant. Place it as the first entry in the messages array.
python

Stream the response

Set stream: true to receive tokens as server-sent events (SSE) instead of waiting for the full response. This reduces perceived latency for long outputs.

Switch models

Change the model parameter to route your request to a different provider. TokModel uses the format provider/model-name. No other code changes are needed.
python
Browse all available models and their provider slugs in the Models reference.

Multi-turn conversation

Build a conversation history by appending each assistant reply to the messages array before sending the next user message.
python