{"uid":"cap_J-vxF4cIUdPCooRh_uHZT","slug":"onhub-chat-completions-api-d3f27ef2","name":"OnHub Chat Completions API","description":"Text completion using the model selected in the request body.","url":"https://x402.onhub.ai/v1/chat/completions?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"model":{"type":"string","description":"Optional; must match the model in the selected route."},"stream":{"type":"boolean","const":false,"default":false},"messages":{"type":"array","items":{"type":"object","required":["role","content"],"properties":{"role":{"enum":["system","user","assistant"],"type":"string"},"content":{"type":"string"}},"additionalProperties":false},"minItems":1},"max_tokens":{"type":"integer","default":1024,"maximum":2048,"minimum":1},"temperature":{"type":"number","maximum":2,"minimum":0},"enable_thinking":{"type":"boolean","description":"For reasoning-capable Workers AI models. Defaults to false for GPT-OSS chat reliability."},"reasoning_effort":{"enum":["low","medium","high",null],"type":["string","null"],"description":"For reasoning-capable Workers AI models."}}},"responseSchema":{"type":"json","example":{"model":"openai/gpt-oss-20b","object":"chat.completion","choices":[{"index":0,"message":{"role":"assistant","content":"Hello."},"finish_reason":"stop"}]}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.002","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","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.002/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.002","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.002","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_djo-CHajrTgffOvlYsr5v","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.002","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Pay-per-request LLM text inference endpoint using OpenAI-compatible chat completions format, billed per call in USDC on Base","exampleAgentPrompt":"Using OnHub's pay-per-request inference, send this conversation to the gpt-oss-20b model with a max of 512 tokens and temperature 0.7: system says 'You are a concise assistant', and the user asks 'Summarize the key differences between TCP and UDP in two sentences.'","exampleUseCases":[{"title":"Agent pipeline LLM call with micropayment","prompt":"Send this multi-turn conversation to OnHub's chat completions endpoint using the gpt-oss-20b model, max 1024 tokens, temperature 0.5 — I want to pay per request in USDC instead of committing to a subscription. Messages: system 'You are a helpful coding assistant', user 'How do I debounce a function in JavaScript?'"},{"title":"Reasoning task with thinking enabled","prompt":"Call OnHub's inference API with enable_thinking turned on and reasoning_effort set to high. Use gpt-oss-20b, up to 2048 tokens, and ask: 'Given these three business options, which has the best 5-year ROI potential and why?' I want the model to reason carefully before answering."},{"title":"Autonomous agent step execution","prompt":"My agent needs to process this user query as part of a workflow — hit the OnHub chat completions endpoint, model gpt-oss-20b, temperature 0.3, max 256 tokens, system prompt 'Extract structured JSON from the user message', user message 'Order ID 4821, shipped on Jan 3rd, delivered Jan 7th, customer complained about damaged packaging.'"}],"resultDescription":"Returns an OpenAI-compatible chat completion JSON object containing the model name, an array of choices each with an assistant message and finish reason (e.g. 'stop'), and the object type 'chat.completion'. No streaming — response is returned as a complete JSON payload after inference.","failureModes":["Payment not provided or insufficient USDC balance — 402 Payment Required returned","Model name mismatch with the selected route — request may fail or route incorrectly","messages array empty or missing required role/content fields — 400 Bad Request","max_tokens exceeds 2048 limit — validation error","stream set to true — rejected as only non-streaming (const false) is supported","Temperature outside 0-2 range — validation error","Network or Workers AI backend unavailability — 500 or timeout"],"whenToPreferThis":"Choose this endpoint when you want OpenAI-compatible chat completions billed as micropayments in USDC on Base with no subscription commitment — ideal for agentic pipelines that need pay-per-request economics, crypto-native payment rails, or want to avoid API key management. Prefer over standard OpenAI or Anthropic APIs when building crypto-native agents or when cost predictability per call matters more than model variety.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-12T21:40:03.523Z","isFirstParty":false,"canonicalSlug":"onhub-chat-completions-api-d3f27ef2"}