Documentation menu

Quickstart

Create a key, send a request for a customer, read its usage and give the customer credit.

In this guide you send your first request through the gateway, find it in the usage log and give the customer it was made for some credit. You work in the Staging environment, which answers from a mock instead of calling a provider, so nothing here costs money.

You need an account on the dashboard with a project, and curl.

Create a key#

In the dashboard, open your project and switch to the Staging environment. Go to Developers → API keys and create a key with both scopes, inference and management: you will use it for the gateway and for the management API.

Copy the secret. It starts with hx_sk_test_ because Staging is a test environment, and it is shown only once. Keep it in an environment variable:

export HIXEL_API_KEY="hx_sk_test_…"

Send a request for a customer#

Call the gateway as you would call OpenAI, with two extra headers: x-hixel-customer names your customer (your own id for it) and x-hixel-member the person who asked.

curl -i https://api.hixel.dev/v1/responses \
  -H "Authorization: Bearer $HIXEL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-hixel-customer: org_42" \
  -H "x-hixel-member: user_7" \
  -d '{ "model": "gpt-6.2-sol", "input": "Write a haiku about invoices." }'

The answer has the shape OpenAI's Responses API gives, and these headers among others:

x-hixel-request-id: req_6f1c0e9a2b7d4c3e8a5f0b1d2c3e4f5a
x-hixel-model: gpt-6.2-sol
x-hixel-mock: true

x-hixel-mock: true says the Staging mock answered. In Production the same request reaches the provider on your own provider key, which you connect before the first request there. Keep the request id: it is how you find this request later and how support finds it.

The first request that names org_42 also creates the customer.

Read the request's usage#

Every request is recorded with its customer, member, model, token counts and cost. Recording happens just after the response, so give it a few seconds, then look the request up by its id with the management API:

curl "https://api.hixel.dev/v1/usage?request_id=req_6f1c0e9a2b7d4c3e8a5f0b1d2c3e4f5a" \
  -H "Authorization: Bearer $HIXEL_API_KEY"
{
  "data": [
    {
      "id": "use_…",
      "request_id": "req_6f1c0e9a2b7d4c3e8a5f0b1d2c3e4f5a",
      "customer": "org_42",
      "member": "user_7",
      "model": "gpt-6.2-sol",
      "payer": "tenant",
      "mocked": true,
      "tokens": { "input": "14", "cache_read": "0", "cache_write_5m": "0", "cache_write_1h": "0", "output": "21", "reasoning": "0" },
      "cost_micros": "198",
      "billed_micros": "198",
      "outcome": "completed",
      …
    }
  ],
  "next_cursor": null
}

Token counts and amounts are strings of integers; amounts are micro-USD, so "198" is $0.000198. The same request is in the dashboard under Observability → Requests.

Give the customer credit#

payer is tenant above: until you turn wallets on, requests are paid from your organization's account and no customer balance is checked. Turn them on in Credits → Settings (“Pay customers' requests from their wallets”), or from code: changing gateway settings takes a project key with the admin role (create one under Settings › Project › Project keys), naming the environment.

curl -X PATCH https://api.hixel.dev/v1/gateway \
  -H "Authorization: Bearer $HIXEL_PROJECT_KEY" \
  -H "x-hixel-environment: env_k3j9x2m8q1w7e4r5t6y0u2i3" \
  -H "Content-Type: application/json" \
  -d '{ "wallet": { "enabled": true } }'

From then on, a request that names a customer is paid from that customer's wallet and refused with 402 when the wallet cannot cover it.

Grant org_42 five dollars:

curl https://api.hixel.dev/v1/customers/org_42/grants \
  -H "Authorization: Bearer $HIXEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount_micros": "5000000",
    "idempotency_key": "welcome-credit-org_42",
    "reason": "Welcome credit"
  }'

The answer is the new ledger entry. The idempotency_key makes the grant safe to retry: the same key grants once, however often you send it. Send the request from step 2 again and read the wallet:

curl https://api.hixel.dev/v1/customers/org_42/wallet \
  -H "Authorization: Bearer $HIXEL_API_KEY"

balance.total_micros is a little under "5000000": the second request was paid from the grant.

Next steps#

  • Sending requests: the three API formats, streaming and every header.
  • Limits: cap a customer's spend per day or month.
  • Webhooks: hear about low balances instead of polling.
  • Top-ups: let customers buy credit through your Stripe account.
  • Manage a project from code: environments, keys and gateway settings with a project key.
  • Before Production: connect your provider keys to the Production environment (its requests run on your own OpenAI, Anthropic or Google account, and a model without a key is refused), then create a Production key, which starts with hx_sk_ and calls real providers.