Skip to content

Start here

Quickstart

Go from a private request to your first metered chat completion with an OpenAI SDK.

On this page

This walks from nothing to a metered chat completion. On the sandbox route today the whole flow takes a few minutes and costs nothing, because sandbox agreements settle with no charge.

1. Get an allocation

An API key only works against an allocation, and an allocation only exists after an agreement activates. In the Cairva workspace:

  1. Sign in and create a buyer organization.
  2. Open Requests and send a private request for the model, token volume and delivery window you need. Pick at least one verified supplier, or request terms directly on a lot from the market.
  3. When a supplier issues a firm quote, review it in the deal room and accept that version. Only an organization admin can accept.
  4. The supplier countersigns. For a live agreement you pay the invoice and Cairva operations confirm it. Sandbox agreements skip payment.
  5. Activation checks run and the allocation goes live, or becomes ready if its window hasn't opened yet.

The full sequence is in How Cairva works.

2. Create a key

Open API keys in the workspace, choose the allocation, give the key a name and pick its scopes. Use inference to call models and usage:read to read the allocation and usage. The secret is shown once. Store it as an environment variable on the machine that will make requests:

Terminal
export CAIRVA_API_KEY="cv_test_XXXXXXXX_..."

Sandbox allocations get cv_test_ keys and live allocations get cv_live_ keys. See API keys.

3. Check what the key can call

GET /v1/models returns the single model your allocation covers. That id is the only value model can take.

curl https://cairva.xyz/v1/models \
  -H "Authorization: Bearer $CAIRVA_API_KEY"

4. Send a request

curl https://cairva.xyz/v1/chat/completions \
  -H "Authorization: Bearer $CAIRVA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemma4:e2b",
    "messages": [{"role": "user", "content": "Name three uses for a token allowance."}],
    "max_tokens": 300
  }'

Replace gemma4:e2b with whatever /v1/models returned for your key. Any other value fails with model_not_permitted.

Tip

Set max_tokens to what you actually need. Cairva holds that many output tokens from your allowance while the request runs, and caps it at what's left. See Rate limits and holds.

5. Watch the meter

Terminal
curl https://cairva.xyz/v1/allocations/current \
  -H "Authorization: Bearer $CAIRVA_API_KEY"

remaining drops by the tokens the provider reported for your request. Each request also appears in once its usage is booked.

If something fails

You seeLikely cause
401 unauthenticatedThe key is missing, mistyped or revoked
403 scope_missingThe key doesn't have inference (for completions) or usage:read (for allocation and usage)
403 model_not_permittedmodel isn't the id from /v1/models
403 allocation_not_startedThe delivery window hasn't opened
502 upstream_errorThe route didn't complete the request. Nothing was charged

Every code is listed in Errors.