{"uid":"cap_zljDFvkGDRNSJzPvrtiS0","slug":"openrouter-withzero-xyz-openrouter-multi-model-chat-completion-gateway-afc45be7","name":"OpenRouter Multi-Model Chat Completion Gateway","description":"OpenAI-compatible chat completion via any OpenRouter model, paid in one shot: price = estimated input tokens x input rate + max_tokens x output rate, resolved before the call and capped per model (from $0.10 for cheap models up to $5 for premium models like anthropic/claude-fable-5). For longer generations use POST /api/v1/chat/completions/metered. 📖 Full guide: https://openrouter.withzero.xyz/llms.txt","url":"https://openrouter.withzero.xyz/api/v1/chat/completions","method":"POST","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","example":{"model":"openai/gpt-4o-mini","messages":[{"role":"user","content":"Say hello in one sentence."}],"max_tokens":64},"required":["model","messages","max_tokens","stream"],"properties":{"seed":{"type":"integer","maximum":9007199254740991,"minimum":-9007199254740991,"description":"Random seed for deterministic outputs (support varies by model)."},"stop":{"anyOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}],"description":"Stop sequence(s): generation halts when any is produced."},"model":{"type":"string","minLength":1,"description":"OpenRouter model ID, e.g. \"openai/gpt-4o-mini\", \"anthropic/claude-haiku-4-5\", \"google/gemini-flash-1.5\". Use GET /api/v1/models to list all available models with pricing."},"route":{"type":"string","description":"OpenRouter routing strategy, e.g. \"fallback\". Requires an explicit `models` list so every candidate model can be priced."},"tools":{"type":"array","items":{},"description":"OpenAI-format tool definitions for function calling."},"top_k":{"type":"integer","maximum":9007199254740991,"minimum":0,"description":"Top-k sampling: limit to the k most likely next tokens."},"top_p":{"type":"number","maximum":1,"minimum":0,"description":"Nucleus sampling probability mass 0–1. Alternative to temperature."},"models":{"type":"array","items":{"type":"string"},"description":"Fallback model list for OpenRouter auto-routing. Tried in order if the primary model is unavailable. The price reservation is taken at the most expensive rates across model + models, since any of them may serve the call; the difference is refunded on the metered route."},"stream":{"type":"boolean","const":false,"default":false,"description":"Must be false — streaming is not supported in v1."},"messages":{"type":"array","items":{"type":"object","required":["role","content"],"properties":{"name":{"type":"string","description":"Optional display name for the message author"},"role":{"enum":["system","user","assistant","tool"],"type":"string","description":"Message role: system (instructions), user (human turn), assistant (model turn), or tool (tool result)"},"content":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Message text content, or null for tool-call-only assistant turns"},"tool_calls":{"type":"array","items":{},"description":"For role=assistant: tool calls the model is making"},"tool_call_id":{"type":"string","description":"For role=tool: the tool_call_id this result responds to"}},"additionalProperties":false},"minItems":1,"description":"Conversation history as an array of {role, content} objects. At minimum one user message is required."},"reasoning":{"type":"object","properties":{"effort":{"enum":["none","minimal","low","medium","high","xhigh"],"type":"string","description":"Reasoning effort level. Mutually exclusive with max_tokens."},"enabled":{"type":"boolean","description":"Enable reasoning at the default (medium) effort."},"exclude":{"type":"boolean","description":"Generate reasoning but omit it from the response."},"max_tokens":{"type":"integer","maximum":9007199254740991,"description":"Explicit reasoning token budget.","exclusiveMinimum":0}},"description":"OpenRouter reasoning config for thinking models. Reasoning tokens bill as output tokens and are added to the price reservation.","additionalProperties":false},"logit_bias":{"type":"object","description":"Token ID → bias (-100 to 100) to adjust generation likelihood.","propertyNames":{"type":"string"},"additionalProperties":{"type":"number"}},"max_tokens":{"type":"integer","default":4096,"maximum":9007199254740991,"description":"Maximum output tokens. Controls your spend ceiling — the price reservation is input estimate x input_rate + (max_tokens + reasoning budget) x output_rate. The fixed route rejects requests reserving above its cap; use the metered route for large values.","exclusiveMinimum":0},"transforms":{"type":"array","items":{"type":"string"},"description":"OpenRouter prompt transforms, e.g. [\"middle-out\"] for context compression."},"temperature":{"type":"number","maximum":2,"minimum":0,"description":"Sampling temperature 0–2. Higher = more random. Defaults to model default (usually ~1.0)."},"tool_choice":{"description":"Tool selection strategy: \"auto\", \"none\", \"required\", or a specific tool name."},"response_format":{"type":"object","required":["type"],"properties":{"type":{"type":"string"}},"description":"Output format, e.g. {\"type\":\"json_object\"} to force JSON output.","additionalProperties":false},"presence_penalty":{"type":"number","description":"Penalise tokens that have appeared at all in the context (-2 to 2)."},"frequency_penalty":{"type":"number","description":"Penalise tokens proportional to how often they already appear (-2 to 2)."},"repetition_penalty":{"type":"number","description":"Repetition penalty multiplier (1.0 = no penalty). Some models only."}},"additionalProperties":false},"responseSchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["id","object","created","model","choices","billing"],"properties":{"id":{"type":"string"},"model":{"type":"string"},"usage":{"type":"object","required":["prompt_tokens","completion_tokens","total_tokens"],"properties":{"cost":{"type":"number"},"total_tokens":{"type":"number"},"prompt_tokens":{"type":"number"},"completion_tokens":{"type":"number"}},"additionalProperties":false},"object":{"type":"string"},"billing":{"type":"object","required":["promptTokens","completionTokens","reservedUsdcMicro","settledUsdcMicro","actualUsdcMicro","costBasis"],"properties":{"costBasis":{"enum":["openrouter","rates","estimated"],"type":"string","description":"Where actualUsdcMicro came from: OpenRouter usage accounting > cached per-token rates > character estimate"},"promptTokens":{"type":"number","description":"Actual input tokens consumed"},"actualUsdcMicro":{"type":"string","description":"Best-known actual cost of the call in micro-USDC. On the fixed route this is informational — the charge is settledUsdcMicro."},"completionTokens":{"type":"number","description":"Actual output tokens generated"},"settledUsdcMicro":{"type":"string","description":"Micro-USDC actually charged to the buyer. Fixed route: the up-front worst-case estimate (= reservedUsdcMicro). Metered route: actual usage (= actualUsdcMicro)."},"reservedUsdcMicro":{"type":"string","description":"Worst-case micro-USDC committed before the call"}},"additionalProperties":false},"choices":{"type":"array","items":{"type":"object","required":["index","message","finish_reason"],"properties":{"index":{"type":"number"},"message":{"type":"object","required":["role","content"],"properties":{"role":{"type":"string"},"content":{"anyOf":[{"type":"string"},{"type":"null"}]},"tool_calls":{"type":"array","items":{}}},"additionalProperties":false},"logprobs":{},"finish_reason":{"anyOf":[{"type":"string"},{"type":"null"}]}},"additionalProperties":false}},"created":{"type":"number"},"system_fingerprint":{"type":"string"}},"additionalProperties":false},"example":null,"exampleRequest":null,"tags":[],"displayCostAmount":"0.005444","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"settled","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.005444/call","primary":{"kind":"static","protocol":"mpp","network":"tempo","amountUsd":"0.001","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"mpp","network":"tempo","amountUsd":"0.001","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_dMwLTj4Eav0lS0AijE5EB","protocol":"mpp","methodType":"crypto","chain":"tempo","mode":"charge","costAmount":"0.001","costPer":"request","priority":0,"asset":null,"unit":"request","depositMicros":null,"planRef":null}],"brandName":"openrouter.withzero.xyz","brandSlug":"openrouter-withzero-xyz-mpp","brandBaseUrl":"https://openrouter.withzero.xyz","brandDocsUrl":null,"whatItDoes":"Routes OpenAI-compatible chat completion requests to any of 700+ OpenRouter models, billed at cost per token with no markup","exampleAgentPrompt":"Using the OpenRouter gateway, send this conversation to anthropic/claude-haiku-4.5 with a max_tokens limit of 512 and temperature 0.7: system message 'You are a helpful assistant', user message 'Summarize the water cycle in 3 bullet points.'","exampleUseCases":[{"title":"Compare responses across multiple models","prompt":"Send this prompt to both google/gemini-flash-1.5 and meta-llama/llama-3.1-8b-instruct through the OpenRouter gateway: system message 'You are a concise technical writer', user message 'Explain what a REST API is in two sentences.' Use max_tokens of 200 for each and show me both responses so I can compare the output quality."},{"title":"Tool calling with a premium model","prompt":"Using the OpenRouter gateway, send a chat completion request to anthropic/claude-opus-4 with tool calling enabled. System message: 'You are a helpful assistant with access to a weather tool.' User message: 'What is the weather like in Paris right now?' Define a get_weather tool with a location parameter, set max_tokens to 512, and return whatever tool_call the model produces."},{"title":"Budget-capped creative writing generation","prompt":"Via the OpenRouter gateway, send a creative writing request to mistralai/mistral-small with a max_tokens budget of 1024 so I stay within a low cost cap. System message: 'You are a creative fiction author', user message: 'Write the opening paragraph of a mystery novel set in 1920s New Orleans.' Use temperature 0.9 for more creative output."}],"resultDescription":"Returns an OpenAI-compatible chat completion object containing: the generated message text, role, optional tool_call arrays, finish_reason, token usage counts (prompt, completion, total), and a billing object showing promptTokens, completionTokens, and settledUsdcMicro (the actual USDC cost charged for the request).","failureModes":["Model ID not found on OpenRouter — returns error if model string is invalid or unavailable","Insufficient USDC balance to cover estimated cost — call rejected before execution","max_tokens set too low — completion truncated at finish_reason='length'","messages array empty or malformed — schema validation error","stream:true submitted — rejected because only stream:false is supported","Network timeout to upstream OpenRouter — propagated as gateway error","Rate limiting from upstream provider for selected model"],"whenToPreferThis":"Choose this endpoint when you need to access multiple LLM providers (OpenAI, Anthropic, Google, Meta, Mistral, etc.) through a single OpenAI-compatible interface without managing separate API keys or subscriptions. Especially useful when you want transparent, at-cost token billing via crypto micropayments, need fallback model routing, or want to switch between model providers without changing your integration code.","instructions":"# Chat completion — metered, pay-per-call LLM proxy\n\n## Workflow\n- Discover valid `model` IDs and their live per-token rates: GET /api/v1/models (sibling).\n\n## Contract\n- Metered MPP: the price resolved before the call is an escrow/hold, not the final charge. Actual settlement is at-cost from real token usage and the unused difference is refunded — read `usage` and `billing.settledUsdcMicro` in the response for what you actually paid.\n- `max_tokens` sets the escrow ceiling (output rate × max_tokens), so over-sizing it locks up more deposit than a short reply will spend. Size it to the real reply length you need.","reviewSummary":"OpenAI-compatible chat completions routed through OpenRouter with upfront flat-fee pricing. Successful calls deliver accurate outputs with valid JSON responses and reasonable gateway latency (~2.9s); error handling is informative, correctly surfacing model-unavailability signals with minimal charge. However, a HTTP 409 'usage_not_priced' error was encountered before payment or model execution on at least one valid request, indicating reliability gaps in the pricing resolution step.","reviewSummaryHighlights":["Accurate model outputs with valid JSON and transparent token reporting","Informative error responses for unavailable or access-gated models","Flat upfront pricing is cost-effective for short-to-medium generations"],"reviewSummaryConcerns":["HTTP 409 usage_not_priced errors can block execution before any model call is made","Flat-fee model may overcharge for short completions capped at max_tokens"],"reviewSummaryGeneratedAt":"2026-07-23T20:15:06.436Z","activationCount":3,"lastUsedAt":"2026-07-29T00:21:26.035Z","lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-15T18:36:59.506Z","isFirstParty":true}