Skip to main content
OpenAI-compatible chat completions, routed through OpenRouter. The request body is OpenRouter’s (a superset of OpenAI’s) and is forwarded as-is — see OpenRouter’s API reference for every field. Set stream: true for Server-Sent Events.
string
required
Model id with provider prefix, e.g. anthropic/claude-sonnet-4.6, openai/gpt-5.2.
array
OpenAI-style chat messages: [{ role, content }]. Either messages or prompt is required.
string
Plain-text prompt (alternative to messages).
string[]
Optional fallback chain — OpenRouter tries these in order if earlier models are unavailable.
object
OpenRouter provider routing preferences (order, only, ignore, sort, allow_fallbacks, data_collection, …).
boolean
default:"false"
Stream the response as SSE. The final chunk carries the usage (incl. cost).
number
Sampling temperature (0–2). top_p, max_tokens, stop, seed, tools, tool_choice, response_format, etc. are also forwarded.
Detecting truncated output. When a completion hits the token cap, the output is silently cut off and choices[0].finish_reason is "length". In that case the response also carries a top-level "truncated": true flag — check it (or finish_reason) before treating the output as complete, and re-request with a higher max_tokens if needed. The flag is absent (not false) when the generation finished cleanly. The naive llm chat CLI additionally prints a warning to stderr.
Cost: per-token, derived from OpenRouter’s returned usage.cost × markup (see Credits). Charged after completion (after the final SSE chunk for streams).
Prefer to keep your existing OpenAI/OpenRouter SDK? Point its baseURL at https://api.usenaive.ai/v1/proxy/openrouter and authenticate with your Naive api key — a transparent, drop-in passthrough. See Use Naive instead of OpenRouter.