/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 theAuthorization header:
Send a basic request
The minimum required fields aremodel 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 inchoices[0].message.content.
Use a system message
Asystem message sets the behavior and context for the assistant. Place it as the first entry in the messages array.
python
Stream the response
Setstream: 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 themodel parameter to route your request to a different provider. TokModel uses the format provider/model-name. No other code changes are needed.
python
Multi-turn conversation
Build a conversation history by appending each assistant reply to themessages array before sending the next user message.
python
