Chat (OpenAI)
Generate model responses from a list of messages. Fully OpenAI-compatible; streaming, function calling and structured output are controlled through request parameters.
Authorization
$WYLON_API_KEY and send it in the authorization header. Create API keys in the dashboard.Request body
Content-Type: application/json
moonshotai/Kimi-K2. The available list is in the model catalog or via the list models endpoint.
role and content.
system, user, assistant or tool.{type, text|image_url}.role="tool"; correlates to the tool-call ID from the previous assistant turn.true, deltas are streamed as SSE (text/event-stream); the stream terminates with data: [DONE].0 – 2. Higher means more random; tune either this or top_p, not both.0 – 1. Samples from the smallest set whose cumulative probability reaches top_p.0 disables.n × completion_tokens.-2.0 – 2.0. Positive values reduce topic repetition and encourage novelty.-2.0 – 2.0. Positive values penalize tokens by frequency, suppressing verbatim repetition.{type: "function", function: {name, description, parameters}}. See Function calling."auto" lets the model decide; "none" disables tools; "required" forces at least one call; or pass {type:"function", function:{name:"..."}} to force a specific function.{type:"json_object"} or {type:"json_schema", json_schema:{...}}. See Structured output.logprobs is true, return per-step top-N candidate probabilities, range 0 – 20.Response
Non-streaming: returns a chat.completion object.
Streaming (stream=true): chunks of chat.completion.chunk are returned as SSE, terminated by data: [DONE].
chat.completion or chat.completion.chunk (streaming).{role, content, tool_calls?}.stop / length / tool_calls / content_filter.{
"id": "cmpl-9f1c7b2e8a41",
"object": "chat.completion",
"created": 1744828800,
"model": "moonshotai/Kimi-K2",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "KV cache stores …" },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 128,
"total_tokens": 152,
"cache_hit_ratio": 0.71
}
}
Bad request, authentication failure, or an exceeded rate limit. Errors use the OpenAI-compatible envelope.
invalid_request_error, authentication_error, rate_limit_exceeded.{
"error": {
"type": "rate_limit_exceeded",
"message": "Rate limit reached for moonshotai/Kimi-K2 on tier 2.",
"retry_after": 3.4
}
}
Transient server error. Retry with exponential backoff and jitter.
{
"error": {
"type": "server_overloaded",
"message": "Upstream model is temporarily unavailable, please retry."
}
}
Error codes and recommended actions
Failed requests return an OpenAI-compatible error object. Check the HTTP status together with error.type, error.code, and error.message.
| HTTP status | Common cause | Recommended action |
|---|---|---|
400 | Missing required fields, invalid types or values, or an unavailable model ID | Correct the request using error.message; do not retry it unchanged |
401 | Missing, invalid, or revoked API key | Check the Authorization: Bearer ... header and key status |
403 | The current identity cannot access the model or endpoint | Check the key's account, tier, and model permissions |
429 | Rate, concurrency, or token limit reached | Honor retry_after or Retry-After, then retry with exponential backoff and jitter |
500, 503 | Internal error or temporary upstream model unavailability | Retry later with exponential backoff and jitter; record the public error fields if failures continue |
Automatically retry only 429 and transient 5xx errors. Record the HTTP status and public error fields for troubleshooting, never the complete API key.