{"openapi":"3.1.0","info":{"title":"unchain-ai Agent API","version":"1.0.0","description":"An OpenAI-compatible API for our model. Any OpenAI client works: set the Base URL and a token from the bot. Each request charges its actual token cost to your balance."},"servers":[{"url":"https://unchain-ai.com/v1","description":"Agent API"}],"security":[{"bearerAuth":[]}],"tags":[{"name":"Chat","description":"Response generation"},{"name":"Models","description":"Available models"},{"name":"Account","description":"Balance, limits and usage"}],"paths":{"/models":{"get":{"tags":["Models"],"operationId":"listModels","summary":"List models","description":"Returns the only model the API serves. Checks the token.","responses":{"200":{"description":"List of models","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModelList"},"example":{"object":"list","data":[{"id":"unchain-ai","object":"model","created":0,"owned_by":"unchain-ai"}]}}}},"401":{"description":"The token is missing or revoked","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"examples":{"invalid_api_key":{"value":{"error":{"message":"Токен недействителен: выпусти новый в боте. / Invalid API key: issue a new one in the bot.","type":"authentication_error","code":"invalid_api_key"}}}}}}}}}},"/me":{"get":{"tags":["Account"],"operationId":"getAccount","summary":"Balance and usage","description":"The token owner's balance, whether requests can be sent right now, the model, limits and usage over the last 24 hours and 30 days. Only charged requests count. Free.","responses":{"200":{"description":"Account state","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Account"},"example":{"object":"account","balance_usd":4.2531,"min_balance_usd":0.1,"can_request":true,"model":"unchain-ai","max_concurrent_requests":3,"token":{"last4":"a1b2","created":1760000000},"usage":{"last_24h":{"requests":42,"spent_usd":0.318,"input_tokens":512000,"output_tokens":38000},"last_30d":{"requests":610,"spent_usd":4.91,"input_tokens":7800000,"output_tokens":560000}}}}}},"401":{"description":"The token is missing or revoked","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"examples":{"invalid_api_key":{"value":{"error":{"message":"Токен недействителен: выпусти новый в боте. / Invalid API key: issue a new one in the bot.","type":"authentication_error","code":"invalid_api_key"}}}}}}}}}},"/chat/completions":{"post":{"tags":["Chat"],"operationId":"createChatCompletion","summary":"Model response","description":"OpenAI Chat Completions format. Streaming (`stream: true`, Server-Sent Events) and tool calls (`tools`) are supported. When streaming, the last chunk before `data: [DONE]` carries `usage`. A user can run a limited number of requests at once; extra ones get 429 with a `Retry-After` header.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletionRequest"},"examples":{"simple":{"summary":"Non-streaming response","value":{"model":"unchain-ai","messages":[{"role":"system","content":"You are a programming assistant."},{"role":"user","content":"Write a sorting function in Python"}]}},"stream":{"summary":"Streaming response","value":{"model":"unchain-ai","stream":true,"messages":[{"role":"user","content":"Hello!"}]}}}}}},"responses":{"200":{"description":"The model's response. With `stream: true`, a `text/event-stream` of `chat.completion.chunk` chunks.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletion"},"example":{"id":"chatcmpl-123","object":"chat.completion","created":1760000000,"model":"unchain-ai","choices":[{"index":0,"finish_reason":"stop","message":{"role":"assistant","content":"def sort_list(items):\n    return sorted(items)"}}],"usage":{"prompt_tokens":24,"completion_tokens":12,"total_tokens":36}}},"text/event-stream":{"schema":{"type":"string"},"example":"data: {\"id\":\"chatcmpl-123\",\"object\":\"chat.completion.chunk\",\"model\":\"unchain-ai\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"Hel\"}}]}\n\ndata: {\"id\":\"chatcmpl-123\",\"object\":\"chat.completion.chunk\",\"model\":\"unchain-ai\",\"choices\":[],\"usage\":{\"prompt_tokens\":9,\"completion_tokens\":5,\"total_tokens\":14}}\n\ndata: [DONE]\n\n"}}},"400":{"description":"The body is not a JSON object or has no `messages`; invalid request parameters","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"examples":{"invalid_request":{"value":{"error":{"message":"Нужен JSON-объект с полем messages. / Body must be a JSON object with messages.","type":"invalid_request_error","code":"invalid_request"}}}}}}},"401":{"description":"The token is missing or revoked","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"examples":{"invalid_api_key":{"value":{"error":{"message":"Токен недействителен: выпусти новый в боте. / Invalid API key: issue a new one in the bot.","type":"authentication_error","code":"invalid_api_key"}}}}}}},"402":{"description":"The balance is below the minimum: top it up in the bot","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"examples":{"insufficient_balance":{"value":{"error":{"message":"Недостаточно средств: пополни баланс в боте. / Insufficient balance: top up in the bot.","type":"insufficient_quota","code":"insufficient_balance"}}}}}}},"413":{"description":"The request body exceeds the size limit","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"examples":{"request_too_large":{"value":{"error":{"message":"Запрос слишком большой. / Request is too large.","type":"invalid_request_error","code":"request_too_large"}}}}}}},"429":{"description":"Too many concurrent requests","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"examples":{"concurrency_limit":{"value":{"error":{"message":"Слишком много одновременных запросов. / Too many concurrent requests.","type":"rate_limit_error","code":"concurrency_limit"}}}}}}},"502":{"description":"The model is temporarily unavailable","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"examples":{"upstream_error":{"value":{"error":{"message":"Модель временно недоступна, попробуй ещё раз. / Model is temporarily unavailable.","type":"server_error","code":"upstream_error"}}}}}}},"503":{"description":"The service is under maintenance","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"examples":{"maintenance":{"value":{"error":{"message":"Сервис на обслуживании, попробуй позже. / Service is under maintenance.","type":"server_error","code":"maintenance"}}}}}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"sk-…","description":"The token is issued in the bot: “AI assistant for code” → “Issue token”."}},"schemas":{"Message":{"type":"object","required":["role"],"properties":{"role":{"type":"string","enum":["system","user","assistant","tool"]},"content":{"description":"Text or an array of message parts (OpenAI format).","oneOf":[{"type":"string"},{"type":"array","items":{"type":"object"}},{"type":"null"}]},"name":{"type":"string"},"tool_calls":{"type":"array","items":{"$ref":"#/components/schemas/ToolCall"}},"tool_call_id":{"type":"string","description":"For `role: tool`: the id of the call this message answers."}}},"Tool":{"type":"object","required":["type","function"],"properties":{"type":{"type":"string","enum":["function"]},"function":{"type":"object","required":["name"],"properties":{"name":{"type":"string"},"description":{"type":"string"},"parameters":{"type":"object","description":"JSON Schema of the arguments."}}}}},"ToolCall":{"type":"object","properties":{"id":{"type":"string"},"type":{"type":"string","enum":["function"]},"function":{"type":"object","properties":{"name":{"type":"string"},"arguments":{"type":"string"}}}}},"ChatCompletionRequest":{"type":"object","required":["messages"],"additionalProperties":true,"properties":{"model":{"type":"string","examples":["unchain-ai"],"description":"Model name. Every request is served by `unchain-ai`, so the field can stay as it is."},"messages":{"type":"array","minItems":1,"items":{"$ref":"#/components/schemas/Message"}},"stream":{"type":"boolean","default":false,"description":"Stream the response (SSE)."},"temperature":{"type":"number","minimum":0,"maximum":2},"top_p":{"type":"number","minimum":0,"maximum":1},"max_tokens":{"type":"integer","minimum":1,"description":"Maximum response length in tokens."},"stop":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]},"tools":{"type":"array","items":{"$ref":"#/components/schemas/Tool"}},"tool_choice":{"description":"`auto`, `none`, `required` or a specific function.","oneOf":[{"type":"string"},{"type":"object"}]},"response_format":{"type":"object","description":"For example `{\"type\": \"json_object\"}`."}}},"ChatCompletion":{"type":"object","properties":{"id":{"type":"string"},"object":{"type":"string","enum":["chat.completion"]},"created":{"type":"integer"},"model":{"type":"string"},"choices":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer"},"message":{"$ref":"#/components/schemas/Message"},"finish_reason":{"type":["string","null"],"examples":["stop","length","tool_calls"]}}}},"usage":{"$ref":"#/components/schemas/Usage"}}},"Usage":{"type":"object","properties":{"prompt_tokens":{"type":"integer"},"completion_tokens":{"type":"integer"},"total_tokens":{"type":"integer"}}},"UsageWindow":{"type":"object","properties":{"requests":{"type":"integer","description":"Charged requests"},"spent_usd":{"type":"number","description":"Charged to the balance, $"},"input_tokens":{"type":"integer"},"output_tokens":{"type":"integer"}}},"Account":{"type":"object","properties":{"object":{"type":"string","enum":["account"]},"balance_usd":{"type":"number","description":"Balance, $"},"min_balance_usd":{"type":"number","description":"Below this balance, requests are rejected with 402"},"can_request":{"type":"boolean","description":"Whether the balance covers a new request"},"model":{"type":"string"},"max_concurrent_requests":{"type":"integer","description":"How many requests can run at once"},"token":{"type":"object","properties":{"last4":{"type":"string","description":"Last 4 characters of the token"},"created":{"type":"integer","description":"When it was issued, Unix time"}}},"usage":{"type":"object","properties":{"last_24h":{"$ref":"#/components/schemas/UsageWindow"},"last_30d":{"$ref":"#/components/schemas/UsageWindow"}}}}},"ModelList":{"type":"object","properties":{"object":{"type":"string","enum":["list"]},"data":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"object":{"type":"string","enum":["model"]},"created":{"type":"integer"},"owned_by":{"type":"string"}}}}}},"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"object","required":["message","type"],"properties":{"message":{"type":"string","description":"Text in Russian and English."},"type":{"type":"string"},"code":{"type":["string","null"]}}}}}}}}