How you sign in
Every request that asks the model for an answer proves who you are with your Mica sign-in token or your license key, a long code that proves you have a subscription. Put the key in a line called a Bearer header:
Authorization: Bearer orc_...
The key would come from MICA_LICENSE_KEY or from ~/.mica/license.json. The server stores only a SHA-256 hash, a scrambled fingerprint of the key, never the key itself. The plan is that you would see the raw key exactly once, at checkout.
Addresses you can call
The chat address follows the OpenAI style, a request shape that many tools already know how to send. The gateway checks your plan and your usage limits. A token is a small piece of text the model reads or writes, and each answer counts its tokens times the model's multiplier. The gateway then passes the request to the model provider behind it. Add model to the request body to choose a model. Leave it out and the server default applies.
curl -s https:///v1/inference/chat/completions \
-H "Authorization: Bearer orc_..." \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Summarize this DRC report"}],
"max_tokens": 500, "temperature": 0.2}'
A successful request (200) returns:
{
"choices": [{"message": {"role": "assistant", "content": "..."}}],
"model": "claude-...",
"usage": {"prompt_tokens": 1234, "completion_tokens": 210,
"multiplier": 1.0, "weighted": 1444.0},
"limits": {"tier": "PRO", "hosted": true, "session_hours": 5.0,
"session": {"used": ..., "limit": ..., "percent": 23.4, "resets_at": "..."},
"weekly": {"used": ..., "limit": ..., "percent": 6.1, "resets_at": "..."}}
}
Every answer includes a limits block: how much of your session window and your weekly window you have used (percent) and when each resets (resets_at, UTC), so the client (the program that calls the gateway) can show it without asking again. usage.weighted is what this answer cost: its tokens times the model's multiplier. GET /v1/inference/models lists the models your plan may use, each with its multiplier, plus the same block.
Ask for your license status and current usage. The answer looks like this:
{
"active": true,
"tier": "PRO",
"email": "[email protected]",
"status": "active",
"current_period_end": 1791484800,
"usage": {
"prompt_tokens": 82000,
"completion_tokens": 31000,
"overage_tokens": 0,
"period": "2026-11"
},
"limits": { ... }
}
usage is a raw monthly count kept for reporting; it does not limit you. limits does. An unknown key returns {"active": false, "status": "unknown_key"}.
A simple health check returns {"ok": true}.
✓ Health and readiness For the operator there are also GET /healthz, which always answers {"status": "ok"}; GET /readyz, which answers 200 only when the database is reachable and a model provider is configured; and GET /metrics, numbers for Prometheus (a tool that collects numbers about a running service), behind a token when one is set.
What the error codes mean
| Code | error | What it means |
|---|
400 | invalid request: ... | The request body is malformed or incomplete. |
400 | model_not_available | The model is not offered: it has no multiplier set, or it is not on the gateway's list. |
401 | missing_license_key | The request has no Authorization: Bearer header. |
401 | invalid_license_key | The license key is not recognized. |
402 | subscription_required | The subscription is not active, for example because it was canceled or revoked. Renew it to get the included model access back. |
403 | not_in_plan | Your plan has no hosted models on this server. |
403 | model_not_in_plan | You are on Free and the model is above the Free multiplier ceiling. Pick a cheaper model or move to Pro. |
429 | limit_reached | Your session window or your weekly window is full. The answer names the window (session or weekly) and when it resets (resets_at). |
500 | upstream error: ... | The model provider behind the gateway failed. Retrying will not help. |
502 | upstream error: ... | The model provider behind the gateway failed for now. It is safe to retry. |
503 | inference_not_configured | The server has no model provider configured. This is a setup problem for the operator (the person who runs the server), not for you. |
503 | limits_misconfigured | The server cannot read its limit settings. This is a setup problem for the operator, not for you. |
The client follows mica/models/hosted.py. Treat 401, 402, 403 and a 429 limit_reached as permanent: retrying will not help before the window resets. Treat 5xx as temporary and retry.
Planned usage limits
There is no monthly token quota. A plan's allowance is spent in two rolling windows, the way Claude and ChatGPT plans work: a 5-hour session window and a weekly window. A window starts with your first request, not on a calendar date. Each answer counts its tokens (the small pieces of text the model reads and writes) times the model's multiplier, which the app shows next to each model. The rules live in mica/billing/limits.py:
| Plan | Models | Allowance |
|---|
| Free | The cheaper models only | A small allowance |
| Pro | Every model the gateway serves | A much larger allowance |
- A model's multiplier says how fast it uses your windows: a 4× model four times as fast as a 1× model, a 0.25× model a quarter as fast.
- Hard stop: once a window is full, new requests get
429 limit_reached, which names the window and when it resets. The request that crosses the line is still answered. Nothing is charged automatically. - The session window closes 5 hours after it opened and the weekly window 7 days after. A subscription marked
past_due keeps working during its grace window. - The allowances and multipliers come from the model makers' published prices and can change.
✓ Verify: per-second and per-minute rate limiting The billing code has no limiter for requests per second or per minute. The session and weekly windows are the only limits it enforces. Do not publish a requests-per-minute figure until one exists.
Running the license server (for the operator, not live)
The gateway is a single Python process (one running program) that uses only the Python standard library, so it needs no extra packages. The setup is described in STRIPE_SETUP.md:
export MICA_STRIPE_SECRET_KEY=sk_live_...
export MICA_STRIPE_WEBHOOK_SECRET=whsec_...
export MICA_STRIPE_PRICE_PRO=price_...
export MICA_UPSTREAM_API_KEY=... # model provider key, held by the operator
export MICA_UPSTREAM_MODEL=...
# models, multipliers and limits: deploy/gateway-limits.env
python -m mica.billing.license_server