Documentation
One OpenAI & Anthropic compatible endpoint — from your first request to error recovery, everything lives on this page.
Get started in three steps
Create an API key
Sign up, then create a key from the dashboard. Keys start with sk-cos. Keep it safe because it is shown only once.
Point the base URL
Swap the base URL in your SDK or tool. Authentication uses the Authorization: Bearer <key> header.
Send your first request
Pick a model from the catalog and send a request as usual. Cost is recorded in the logs immediately.
from openai import OpenAIclient = OpenAI(base_url="https://api.cosmosin.io/v1",api_key="sk-cos...",)resp = client.chat.completions.create(model="deepseek-v4-flash",messages=[{"role": "user", "content": "Hello!"}],)print(resp.choices[0].message.content)
Authentication & API keys
Every request must carry your key in the Authorization: Bearer header. One account can hold many keys — mint separate ones per tool or project.
Authorization: Bearer sk-cos...
Key format
Keys are prefixed sk-cos followed by 48 hex characters. The full secret is shown only once at creation; afterwards the dashboard only shows a masked form (sk-cos…c56789).
Manage keys
Mint and revoke keys from the dashboard. A revoked key stops working immediately. Rotate regularly: mint a new key, update your tools, then revoke the old one. Treat keys like passwords — never put them in client-side code, mobile apps, or public repositories.
Tool configuration
Copy-paste snippets for popular tools. Compatible clients read the environment variables automatically.
Claude Code
export ANTHROPIC_BASE_URL=https://api.cosmosin.ioexport ANTHROPIC_AUTH_TOKEN=sk-cos...# continue as usualclaude "finish the migration"
Cursor
{"openai.baseURL": "https://api.cosmosin.io/v1","openai.apiKey": "sk-cos..."}
Codex
# set the key first: export COSMOSIN_API_KEY=sk-cos...model = "deepseek-v4-flash"model_provider = "cosmosin"[model_providers.cosmosin]name = "CosmosIn"base_url = "https://api.cosmosin.io/v1"env_key = "COSMOSIN_API_KEY"wire_api = "responses"
OpenCode
{"$schema": "https://opencode.ai/config.json","provider": {"cosmosin": {"npm": "@ai-sdk/openai-compatible","options": {"baseURL": "https://api.cosmosin.io/v1","apiKey": "sk-cos..."}}}}
Cline
Provider: OpenAI CompatibleBase URL: https://api.cosmosin.io/v1API Key: sk-cos...Model: deepseek-v4-flash
Continue
name: CosmosInversion: 1.0.0schema: v1models:- name: CosmosInprovider: openaimodel: deepseek-v4-flashapiBase: https://api.cosmosin.io/v1apiKey: sk-cos...roles:- chat- edit- applycapabilities:- tool_use
Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /v1/chat/completions | OpenAI compatible. SSE streaming supported. |
| POST | /v1/messages | Anthropic Messages compatible. |
| POST | /v1/responses | OpenAI Responses compatible; used by Codex CLI. |
| GET | /v1/models | Models your key can call. |
Every endpoint uses the same key. Request bodies and responses follow the compatible OpenAI or Anthropic format — an example for /v1/chat/completions:
{"model": "deepseek-v4-flash","messages": [{ "role": "user", "content": "Hello!" }]}
{"id": "chatcmpl-...","object": "chat.completion","model": "deepseek-v4-flash","choices": [{"message": { "role": "assistant", "content": "Hello! How can I help?" }}],"usage": { "prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21 }}
Streaming
Set stream: true to receive the response incrementally as Server-Sent Events (SSE). Each event carries a JSON delta in the OpenAI streaming format; the connection uses content-type text/event-stream and ends with a data: [DONE] sentinel. Most OpenAI SDKs expose streaming natively — just iterate the chunks.
stream = client.chat.completions.create(model="deepseek-v4-flash",messages=[{"role": "user", "content": "Hello!"}],stream=True,)for chunk in stream:delta = chunk.choices[0].delta.contentif delta:print(delta, end="", flush=True)
Models
Fill the model field with a model name from the catalog — CosmosIn uses real model names, no aliases. The full list with per-token pricing is always up to date on the pricing page; the /v1/models endpoint returns the models your key can call.
Reasoning models
Models with the Reasoning badge in the catalog spend part of their token budget thinking before answering. Control the depth per request with reasoning_effort — higher means deeper answers, more tokens, and higher latency. On non-reasoning models the parameter is ignored, so it is safe to always send. Supported levels follow each model; check the Reasoning badge in the catalog. One note: a max_tokens that is too low can leave the answer looking empty because the budget was spent thinking — raise max_tokens or drop the limit.
{"model": "deepseek-v4-flash","messages": [{ "role": "user", "content": "Hello!" }],"reasoning_effort": "high"}
| Effort | Depth | Use for |
|---|---|---|
| none | Off | Direct answers with no thinking |
| low | Light | Simple tasks that need a touch of care |
| medium | Moderate | Most tasks — the sensible default |
| high | Deep | Hard math, multi-step coding, planning |
Embeddings
Turn text into vectors for semantic search, clustering, and retrieval-augmented generation (RAG). Compatible with the OpenAI Embeddings API: send input, receive float vectors. Embeddings do not stream — the stream flag is rejected.
from openai import OpenAIclient = OpenAI(base_url="https://api.cosmosin.io/v1", api_key="sk-cos...")res = client.embeddings.create(model="text-embedding-3-small", input="Hello!")print(res.data[0].embedding[:5]) # [0.012, -0.034, 0.041, ...]
Rerank
Re-order retrieved candidates so the most relevant documents come first. Rerank uses a cross-encoder that reads the query and document together — more accurate than cosine similarity for picking the best context. The common RAG pattern: embed ±20 candidates via /v1/embeddings, rerank to top-5, then feed to chat completions.
- query — the search text (string)
- documents — array of candidate documents to score
- top_n — optional; limit the number of results
- model — the rerank model name
import requestsres = requests.post("https://api.cosmosin.io/v1/rerank",headers={"Authorization": "Bearer sk-cos..."},json={"model": "rerank-v3","query": "rerank","documents": docs, # 10-20 kandidat"top_n": 5,},)for r in res.json()["results"]:print(r["index"], r["relevance_score"])
Video generation
Create short MP4 clips from text or images with one endpoint. The gateway handles the async task server-side: POST returns an id with status pending (HTTP 202), then poll GET /v1/videos/{id} every ~5 seconds until status is succeeded — the response carries the download URL. Clips are stored temporarily; download promptly.
| Mode | How the image is used | Images |
|---|---|---|
| t2v | No image — the video is generated purely from the text prompt | 0 |
| i2v | The image becomes the first frame; the model animates it | 1 |
| r2v | Images act as subject/style references for a new scene | 1–3 |
curl --request POST \--url https://api.cosmosin.io/v1/videos \--header "Authorization: Bearer sk-cos..." \--header "Content-Type: application/json" \--data '{"model": "video-t2v","prompt": "Kota mini dari kardus hidup di malam hari","mode": "t2v","duration": 5}'
Rate limits & quotas
Limits follow your plan. Subscription plans are governed by a per-minute request rate and a token pool; PAYG credits never expire and are bounded only by your balance. Breaching a limit returns 429 rate_limited — back off and retry after the window resets. Per-plan limits are shown on the pricing page.
Error codes
First-request errors are almost always 401 or 402: a mis-pasted key or an empty balance. Check the sk-cos prefix, then check your balance on the dashboard.
Error shape
Errors use a single, stable JSON envelope. Switch on the type field rather than parsing the message. The request_id helps correlate a failure with server logs.
{"error": {"type": "rate_limited","message": "Rate limit exceeded. Please retry later.","request_id": "req_..."}}
| Code | Error | Meaning | Recovery |
|---|---|---|---|
| 400 | invalid_request | Invalid body; check request parameters. | Diff your request body against the examples above. |
| 401 | unauthorized | Wrong or revoked key; check the Authorization header. | Mint a new key on the dashboard if yours was revoked. |
| 402 | insufficient_credits | Balance empty; top up on the dashboard. | Top up via QRIS/e-wallet/VA and the balance lands instantly. |
| 404 | model_not_found | Unknown model name; check the catalog. | Copy the model name exactly from the pricing table. |
| 429 | rate_limited | Too fast; slow down and see the Retry-After header. | Follow the Retry-After header, then retry. |
| 503 | all_providers_failed | All routes busy or down; automatic failover is running, retry shortly. | Retry in a few seconds; report it on Telegram if it persists. |
Model combos
Combos are your own virtual model ids (shaped combo/<name>) bundling 1–5 models behind one fallback strategy. The gateway tries panel models one by one within the same request: target 1 fails (402, 403, 500, timeout) → billing released → target 2, and so on. A circuit breaker skips a model during its cooldown, so a failing model costs no latency. Combos are private to their owner — another key calling your combo gets a 404. Manage them on the dashboard.
curl https://api.cosmosin.io/v1/chat/completions \-H "Authorization: Bearer sk-cos..." \-H "Content-Type: application/json" \-d '{"model": "combo/free-pack","messages": [{"role": "user", "content": "Halo!"}]}'
Plans & pricing
Prices in Rupiah, transparent per token per the catalog — no hidden fees. Two ways to pay: PAYG credits (top-up, never expire) and subscription plans with a token pool. Models, prices, and plan limits are always live on the pricing page.