Chat completions
Send conversation messages and read the assistant reply.
POST /v1/chat/completions is the main endpoint for chat and reasoning models.
Request
curl https://www.tokenmoo.com/v1/chat/completions \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Summarise this in one sentence: ..." }
],
"temperature": 0.7,
"max_tokens": 512
}'Message roles
| Role | Purpose |
|---|---|
system | Instructions that apply to the whole conversation |
user | Input from the caller |
assistant | Previous model replies, for multi-turn context |
Multi-turn conversations
Send the full history on every request — the API is stateless:
{
"model": "gpt-4o-mini",
"messages": [
{ "role": "user", "content": "What is TokenMoo?" },
{ "role": "assistant", "content": "TokenMoo is a unified AI API gateway." },
{ "role": "user", "content": "How do I call it?" }
]
}Practical tips
- Keep
systemshort and explicit; it is billed as input tokens. - Set
max_tokensto bound cost and latency for interactive applications. - Lower
temperature(0–0.3) for factual output, higher for creative output. - Prefer streaming for chat UIs so the user sees tokens as they arrive.