Skip to content
Cosvexa – Cosvexa home

Developers

API reference

Every v1 endpoint, request and response fields, Cosvexa-specific headers, error codes and rate limits.

Endpoints

Method and pathDescription
POST /chat/completionsChat completion with streaming and tool calling (OpenAI-compatible).
POST /chat/stopStops a running chat completion that you named with the x-cosvexa-stop-id header (body {"id":"…"}).
POST /followups2–4 suggested next messages for the last exchange.
GET /modelsModels the workspace can use, with capabilities, data policy and prices.
GET /accountWorkspace plus available and held credits.
GET /images/modelsImage generation models.
POST /images/generationsGenerates images (returned as base64 and also saved to the Library).
POST /images/upscaleUpscales an image to 2K or 4K (returned like generations and saved to the Library).
GET /videos/modelsVideo models with per-second prices, resolutions, aspect ratios and lengths.
POST /videosStarts a video job; credits are charged when the video is ready.
GET /videos/{id}A video job's status and progress; once finished, its file_id and the credits charged.
GET /videos/{id}/contentThe finished MP4.
GET /libraryLibrary items (images, videos, audio, documents and texts), newest first.
GET /library/{id}/contentAn item's file; text items as Markdown.
POST /web/searchWeb search; returns titles, URLs and snippets.
POST /supportOpens a support ticket for the key's owner.

Free keys can call /chat/completions (Cosvexa-1), /chat/stop, /models, /account, /web/search, /library and /support. /followups, /images and /videos need Pro, Team or Enterprise.

POST /chat/completions

FieldDescription
modelRequired. A model id or cosvexa-auto.
messagesRequired. Roles: system, developer (treated as system), user, assistant, tool. Content is text or text / image_url parts.
stream, stream_options.include_usageServer-sent event streaming, with usage in the final chunk.
max_tokens / max_completion_tokensMaximum output tokens, capped by the model. If you leave it out, the model's own maximum is used, sized to your balance; you pay only for the tokens actually generated.
temperature0–2.
reasoning_effortlow, medium or high: how much the model thinks. Models without a thinking setting ignore it (cosvexa.reasoning_effort in GET /models); with cosvexa-auto it goes to the model that answers. Thinking is billed as output tokens.
tools, tool_choice, parallel_tool_callsUp to 256 function tools; auto, none, required or a specific function.

OpenAI fields not listed here (top_p, stop, n, response_format, seed, logprobs and so on) are ignored without an error.

Request headers

HeaderDescription
Authorization: Bearer cvx_...Required on every endpoint.
Idempotency-KeyOptional, 1–200 characters, scoped to the workspace. On models served from a dedicated GPU deployment, repeating a request with the same key and body replays the first answer without running or charging again. The same key with a different body is 409 idempotency_key_mismatch; while the first request still runs, 409 request_in_progress; if it failed, 409 idempotent_request_failed. Other models accept the header without deduplicating.
x-cosvexa-stop-idOptional: a UUID you choose for this request. POST /chat/stop with {"id":"…"} stops it as the user's own Stop, before you close the connection.

Response

json
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "claude-sonnet-5-5",
  "choices": [{ "index": 0, "message": { "role": "assistant", "content": "…" }, "finish_reason": "stop" }],
  "usage": { "prompt_tokens": 12, "completion_tokens": 48, "total_tokens": 60 },
  "cosvexa": { "routed_by": "auto", "data_policy": "provider_retention", "credits_charged": 7200 }
}

Units differ

cosvexa.credits_charged and the amounts in error details are in micro-credits (1 credit = 1,000,000). 7200 in the example is 0.0072 credits. GET /account returns whole credits.

Response headers

x-cosvexa-model (the model that answered), x-cosvexa-routed-by (user or auto), x-cosvexa-data-policy (self_hosted, no_retention, provider_retention).

Free keys also get x-cosvexa-free-remaining (free questions left today) and x-cosvexa-free-resets-at (when they renew, ISO 8601) on /chat/completions and /web/search.

Streaming

With stream: true the answer arrives as chat.completion.chunk events; text is in choices[0].delta.content. Tool calls arrive in delta.tool_calls pieces keyed by index: the first piece of each call carries id, type and function.name, later pieces append to function.arguments. The finish chunk has finish_reason (stop, length or tool_calls).

text
data: {"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"call_1","type":"function","function":{"name":"get_weather","arguments":""}}]},"finish_reason":null}]}

data: {"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\"city\":\"Istanbul\"}"}}]},"finish_reason":null}]}

data: {"choices":[{"index":0,"delta":{},"finish_reason":"tool_calls"}]}

data: {"choices":[],"usage":{"prompt_tokens":40,"completion_tokens":12,"total_tokens":52},"cosvexa":{"routed_by":"user","data_policy":"no_retention","credits_charged":1800}}

data: [DONE]

Credits arrive only in the final usage chunk: with stream_options.include_usage, the last chunk before [DONE] has choices: [], usage and cosvexa.credits_charged (micro-credits). Without it the stream doesn't report what the request cost.

An error during the stream (the HTTP status is already 200) is sent as one event with the error's real status, type and code, followed by [DONE]:

text
data: {"error":{"message":"The model rejected the request. Check the messages, tools (JSON schemas, tool_call_id) and parameters.","type":"invalid_request_error","code":"provider_bad_request","status":400}}

data: [DONE]

type, code and status match the non-streaming error of the same code (see Errors below): don't retry a 4xx unchanged; a 5xx can be retried.

GET /models

Returns an OpenAI-style list. Each item's cosvexa field has display_name, family, capabilities, data_policy, context_window and pricing (credits per 1 million input/output tokens). If the input exceeds long_context.over_input_tokens, the whole request is billed at the long-context rate. A virtual cosvexa-auto entry is listed first.

POST /images/generations

bash
curl https://cosvexa.ai/api/v1/images/generations \
  -H "Authorization: Bearer $COSVEXA_API_KEY" -H "Content-Type: application/json" \
  -d '{"prompt":"a lighthouse at dusk","size":"1024x1024","n":1}'

Fields: prompt (1–4,000 characters), model (empty or auto = automatic), size, n (1–4). The response contains data[].b64_json, mime_type and file_id. Your plan must include Studio images.

POST /images/upscale: file_id (an image of the workspace) or image (base64 or a data URL; PNG, JPEG or WebP up to 10 MB), target (2k = 2048 px or 4k = 4096 px on the long side, each with its own price) and an optional model. The response has the same shape as generations; both share one limit.

Fields: query (1–400 characters), max_results (1–10, default 5), news. Not charged separately. Workspaces that enforce strict privacy get 403 privacy_blocked. Send model, the model doing the work. With cosvexa-1, or without model, Cosvexa's own search runs first; if it finds nothing or fails, a backup search provider answers and receives only the query. Strict privacy never uses the backup. 503 search_unavailable is returned only when no search provider could answer.

Free keys can search too, on the same terms as Cosvexa-1 in Free chat (as above). Each call counts as one of the day's 50 free questions and is given back when nothing was found or the search failed. A model other than cosvexa-1 or cosvexa-auto is 402 plan_required.

POST /followups

Fields: messages (the conversation, 1–500 messages; the last user message and the answer after it are used), surface (chat or code), kind, model (the model that answered; without it or with cosvexa-1, Cosvexa-1 writes the suggestions), locale and privacy_mode. The response is {"object":"followups","followups":[…],"cosvexa":{"credits_charged":…}}, charged at the small model's real cost. followups: true on /chat/completions returns them with the answer instead.

Videos

GET /videos/models lists the video models with credits_per_second, resolutions, aspects, min_seconds, max_seconds and what each supports. POST /videos takes prompt (1–4,000 characters), model, seconds, aspect (16:9, 9:16, 1:1, 21:9 where the model lists it), resolution (720p by default or 1080p), audio, start_image_file_id, end_image_file_id and extend_file_id, and answers 202 with the job id. Poll GET /videos/{id} (queued, running, succeeded, failed or canceled, with progress); once it has succeeded, GET /videos/{id}/content returns the MP4 (before that, 409 not_ready). Credits are charged when the video is ready. Your plan must include Studio video.

GET /library

Query: kind (image, video, audio, document or text), q (matches the title or prompt), after and before (ISO dates), limit (1–100, default 30). Each item in data has id, kind, title, prompt, model, created_at, mime, size_bytes, file_name, seconds and aspect. GET /library/{id}/content returns the item's file. Files the key's owner may not read stay hidden.

POST /support

Fields: subject (3–200 characters), body (5–10,000 characters), category (general, billing, models, account, bug, api or other) and priority (low, normal or high). Answers 201 with the ticket's id, subject and status. A person can have up to 20 open tickets.

Errors

json
{ "error": { "message": "…", "type": "insufficient_quota", "code": "insufficient_credits", "details": { "needed": 12000000, "available": 3000000 } } }
StatusCodesWhat to do
400validation, capability_unsupportedFix the request, e.g. pick a model that supports tools.
400provider_bad_requestThe model rejected the request: check the messages, the tools' JSON schemas and the tool_call_id values. Don't retry it unchanged.
401invalid_api_keyCheck the key; it may have been revoked.
402insufficient_credits, budget_exceededAdd credits on Billing.
402free_daily_exhaustedFree: today's 50 Cosvexa-1 questions are used up. They renew at details.resetsAt; a plan continues now.
402plan_requiredFree: only Cosvexa-1 answers (cosvexa-1 or cosvexa-auto); details.plansUrl links the plans.
403plan_required, privacy_blocked, forbiddenUpgrade your plan or pick a model that meets your privacy setting.
403third_party_blockedCosvexa-1 work isn't sent to another provider, and this request needed one. Pick another model or cosvexa-auto.
403email_unverifiedFree: the key's owner has to verify their e-mail address to use the daily questions.
404model_not_foundUse an id from GET /models.
409idempotency_key_mismatch, request_in_progressDon't reuse an Idempotency-Key with a different body.
409idempotent_request_failedThe request first sent with this Idempotency-Key failed; retry with a new key.
409not_readyThe video isn't finished yet; poll GET /videos/{id}.
429rate_limited, capacity_exhaustedWait for the number of seconds in the Retry-After header.
499canceledThe request was stopped before it finished (POST /chat/stop).
5xxmodel_unavailable, no_model_available, internalRetry shortly or pick another model.
503model_maintenanceThe model is under maintenance; pick another model or cosvexa-auto.
504model_warming_timeoutThe model's server was starting and didn't become ready in time; retry in a minute.

Rate limits

ScopeLimit
All v1 calls (per workspace)Pro 60/min, Team 300/min
Free keys (per person)10/min across every endpoint a Free key can call
Per person (optional)Set by agreement; checked before the workspace limit
POST /images/generations10/min per key
POST /images/upscaleShares the 10/min per key of /images/generations
POST /followups60/min per key
POST /web/search30/min per key
POST /videos5/min per key
POST /support5 per 10 minutes per key

Every call counts against the workspace limit, GET /models and GET /account included (on Free, against the per-person limit). Over a limit the answer is 429 rate_limited with a Retry-After header.

Not supported yet

/responses, Anthropic /messages, /embeddings, audio (TTS/STT), /completions, moderation endpoints, webhooks, and per-key scopes or spending limits aren't available yet.