Developers
API quickstart
The OpenAI-compatible Cosvexa API: creating a key, your first request, streaming, tool calling and Auto routing.
The Cosvexa API is OpenAI-compatible for chat completions and the model list: change the base URL in the OpenAI SDK and you're set. On Pro, Team and Enterprise a key uses every model your plan includes; on Free it uses Cosvexa-1 within your 50 free questions a day.
https://cosvexa.ai/api/v1API key
- 1
Open the developer console
Go to the Keys tab on Developer. You need to be an admin or owner of the workspace.
- 2
Create a key
Keys start with
cvx_and are shown only once; store yours somewhere safe right away. We keep only a hash. - 3
Use it
Send
Authorization: Bearer cvx_...with every request. You can revoke the key on the same page.
Never put your key in browser code or a public repository. The API doesn't allow cross-origin browser calls (CORS); call it from your server.
First request
curl https://cosvexa.ai/api/v1/chat/completions \
-H "Authorization: Bearer $COSVEXA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"cosvexa-auto","messages":[{"role":"user","content":"Hello"}]}'With the OpenAI SDK (Python)
from openai import OpenAI
client = OpenAI(base_url="https://cosvexa.ai/api/v1", api_key="cvx_...")
res = client.chat.completions.create(
model="cosvexa-auto",
messages=[{"role": "user", "content": "Hello"}],
)
print(res.choices[0].message.content)With the OpenAI SDK (JavaScript)
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://cosvexa.ai/api/v1", apiKey: process.env.COSVEXA_API_KEY });
const res = await client.chat.completions.create({
model: "claude-sonnet-5-5",
messages: [{ role: "user", content: "Hello" }],
});
console.log(res.choices[0].message.content);Choosing a model
cosvexa-auto(orauto): Cosvexa classifies the task and picks a suitable model. The response'smodelfield shows which model answered.- For a specific model, use an
idfrom `GET /models` (e.g.claude-opus-5-5,gpt-6-astra). A specific model is never silently replaced. - Council and Project modes aren't available through the API.
Streaming
curl -N https://cosvexa.ai/api/v1/chat/completions \
-H "Authorization: Bearer $COSVEXA_API_KEY" -H "Content-Type: application/json" \
-d '{"model":"cosvexa-auto","stream":true,"stream_options":{"include_usage":true},
"messages":[{"role":"user","content":"Write a haiku"}]}'The response is text/event-stream: each chunk is a data: {...} line and the stream ends with data: [DONE]. With include_usage, the last chunk carries token usage and the credits charged; without it the stream doesn't report credits. If an error happens mid-stream, data: {"error":{...}} is sent with the error's status and code, followed by [DONE]; see the API reference.
Tool calling (function calling)
{
"model": "cosvexa-auto",
"messages": [{ "role": "user", "content": "What's the weather in Istanbul?" }],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"parameters": { "type": "object", "properties": { "city": { "type": "string" } }, "required": ["city"] }
}
}],
"tool_choice": "auto"
}When the model wants a tool, finish_reason is tool_calls and message.tool_calls is returned. Run the tool yourself and send the result back with role: "tool" and the tool_call_id. In Auto, requests with tools are routed as code tasks; choosing a model without tool support returns 400.
Image input
Use {"type":"image_url","image_url":{"url":"data:image/png;base64,..."}} in the message content. Only base64 data: URLs are accepted (PNG, JPEG, WebP, GIF); remote URLs are refused for security.
All endpoints, error codes and limits: API reference.