{"uid":"cap_l9qdwGoU5OC7Y2XsKO46q","slug":"api-x-router-ai-ca24d984","name":"x-router.ai Chat Completions","description":"AI Chat Completion","url":"https://api.x-router.ai/v1/chat/completions","method":"POST","headers":{},"bodySchema":{"type":"object","required":["messages"],"properties":{"model":{"type":"string","description":"The AI model to use, in 'provider/model' format (e.g. 'openai/gpt-4o-mini', 'anthropic/claude-3.5-sonnet')"},"stream":{"type":"boolean","description":"Enable streaming response"},"messages":{"type":"array","items":{"type":"object","required":["role","content"],"properties":{"role":{"enum":["system","user","assistant"],"type":"string"},"content":{"type":"string"}}},"description":"Array of message objects with role and content"},"max_tokens":{"type":"number","description":"Maximum tokens in response, 1-128000"},"temperature":{"type":"number","description":"Temperature for response randomness, 0-2"}}},"responseSchema":{"type":"object","required":["x402Version","accepts","error","_x402","_paymentRequired","_wwwAuthenticate"],"properties":{"_x402":{"type":"boolean"},"error":{"type":"string"},"accepts":{"type":"array","items":{"type":"object","required":["scheme","network","maxAmountRequired","resource","description","mimeType","outputSchema","payTo","maxTimeoutSeconds","asset","extra"],"properties":{"asset":{"type":"string"},"extra":{"type":"object","required":["name","version"],"properties":{"name":{"type":"string"},"version":{"type":"string"}}},"payTo":{"type":"string"},"scheme":{"type":"string"},"network":{"type":"string"},"mimeType":{"type":"string"},"resource":{"type":"string"},"description":{"type":"string"},"outputSchema":{"type":"object","required":["input","output"],"properties":{"input":{"type":"object","required":["type","method","discoverable","bodyType","bodyFields"],"properties":{"type":{"type":"string"},"method":{"type":"string"},"bodyType":{"type":"string"},"bodyFields":{"type":"object","required":["messages","model","max_tokens","temperature","stream"],"properties":{"model":{"type":"object","required":["type","description"],"properties":{"type":{"type":"string"},"description":{"type":"string"}}},"stream":{"type":"object","required":["type","description"],"properties":{"type":{"type":"string"},"description":{"type":"string"}}},"messages":{"type":"object","required":["type","description","required"],"properties":{"type":{"type":"string"},"required":{"type":"boolean"},"description":{"type":"string"}}},"max_tokens":{"type":"object","required":["type","description"],"properties":{"type":{"type":"string"},"description":{"type":"string"}}},"temperature":{"type":"object","required":["type","description"],"properties":{"type":{"type":"string"},"description":{"type":"string"}}}}},"discoverable":{"type":"boolean"}}},"output":{"type":"object","required":["content","model","usage"],"properties":{"model":{"type":"object","required":["type","description"],"properties":{"type":{"type":"string"},"description":{"type":"string"}}},"usage":{"type":"object","required":["type","properties"],"properties":{"type":{"type":"string"},"properties":{"type":"object","required":["prompt_tokens","completion_tokens","total_tokens"],"properties":{"total_tokens":{"type":"object"},"prompt_tokens":{"type":"object"},"completion_tokens":{"type":"object"}}}}},"content":{"type":"object","required":["type","description"],"properties":{"type":{"type":"string"},"description":{"type":"string"}}}}}}},"maxAmountRequired":{"type":"string"},"maxTimeoutSeconds":{"type":"number"}}}},"x402Version":{"type":"number"},"_paymentRequired":{"type":"boolean"},"_wwwAuthenticate":{"type":"null"}}},"example":{"request":{"model":"openai/gpt-4o-mini","stream":false,"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Explain the difference between supervised and unsupervised learning in two sentences."}],"max_tokens":300,"temperature":0.7},"response":{"id":"gen-1781572020-Vy49LC4AMxURV7icpL9E","model":"openai/gpt-4o-mini","usage":{"total_tokens":98,"prompt_tokens":31,"completion_tokens":67,"prompt_tokens_details":{"audio_tokens":0,"video_tokens":0,"cached_tokens":0,"cache_write_tokens":0},"completion_tokens_details":{"audio_tokens":0,"image_tokens":0,"reasoning_tokens":0}},"object":"chat.completion","choices":[{"index":0,"message":{"role":"assistant","content":"Supervised learning involves training a model on a labeled dataset, where the correct outputs are provided, allowing the model to learn the relationship between input features and their corresponding labels. In contrast, unsupervised learning deals with unlabeled data, where the model identifies patterns and structures within the data without explicit guidance on what the outputs should be.","refusal":null,"reasoning":null},"logprobs":null,"finish_reason":"stop"}],"created":1781572020,"service_tier":null,"system_fingerprint":"fp_f8fd8f170c"}},"exampleRequest":{"model":"openai/gpt-4o-mini","stream":false,"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Explain the difference between supervised and unsupervised learning in two sentences."}],"max_tokens":300,"temperature":0.7},"tags":["x402"],"displayCostAmount":"0.001","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.001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.135168","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.135168","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_0tDcyxi_qsknJzeeLtTOi","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.135168","costPer":"request","priority":0,"asset":null,"unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Routes AI chat completion requests to multiple LLM providers (OpenAI, Anthropic, etc.) via a unified API, billed per-call via x402 micropayments","exampleAgentPrompt":"Using the x-router.ai chat completions endpoint with anthropic/claude-3.5-sonnet, send this conversation and give me a response: system prompt 'You are a helpful assistant', user message 'Explain the difference between supervised and unsupervised learning in two sentences', with temperature 0.7 and max 300 tokens.","exampleUseCases":null,"resultDescription":"Returns a standard OpenAI-compatible chat completion response including the assistant's generated message content, the model used, and token usage statistics (prompt tokens, completion tokens, total tokens).","failureModes":["Payment not included or insufficient — returns x402 payment required response with accepted payment details","Invalid model string format — model must be in 'provider/model' format like 'openai/gpt-4o-mini'","Messages array missing or malformed — required field, returns validation error","Upstream provider unavailable — routing failure if target provider is down","Temperature out of range — must be 0-2","max_tokens out of range — must be 1-128000","Streaming not supported in all contexts — stream:true may require SSE-compatible client"],"whenToPreferThis":"Choose this endpoint when you need a unified LLM gateway that supports multiple providers (OpenAI, Anthropic, etc.) under a single API with x402 micropayment billing. Ideal for agents that need to switch models dynamically or avoid managing separate API keys for each provider. Particularly useful in x402-native payment environments where per-call USDC billing is preferred over subscription keys.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-15T18:32:43.890Z","isFirstParty":false}