Test environments
Build and test your integration against a mock that behaves like the real gateway and costs nothing.
Every environment other than Production is a test environment, such as the Staging every
project starts with. Its keys start with hx_sk_test_. A request to a test environment goes
through every step a live one does (the key, the model, the customer, guardrails, the wallet,
spend and rate limits) and then, instead of calling a provider, a built-in mock answers.
So in a test environment you can:
- integrate with the gateway without a provider account or token costs;
- test your credit flows end to end: with wallets on, mocked requests are priced at the model's catalog price with your markup and debited from test wallets;
- force errors and edge cases on demand with
x-hixel-mock; - connect a Stripe account in test mode and buy credit with Stripe's test cards (Top-ups).
A mocked response carries x-hixel-mock: true, and its usage record says "mocked": true with
"attempts": 0. Test environments never share data with Production: separate keys, customers,
wallets and usage.
The mock's answer#
The mock answers in the format you called, streamed if you asked for a stream, with a short reply text and a usage it computes from the request. For the endpoints beside chat it answers in the format of the provider the model would use: embeddings are deterministic unit vectors, images are a 1×1 PNG, speech is a short silence.
Steering the mock#
Send x-hixel-mock with comma-separated directives:
| Directive | Effect |
|---|---|
status=<400..599> | Answer with a provider-style error of that status, in your format, with no usage |
text=<percent-encoded> | The reply text (percent-decoded; write a comma as %2C) |
tokens=<input>:<output> | The usage to report, and charge |
finish=length | End as if the output limit was reached |
finish=content_filter | End as if the provider's content filter stopped it |
finish=tool_calls | Answer with a tool call (to tool=, or the first tool the request declares) |
tool=<name> | Call that tool |
truncate | Cut the response off half way: a stream stops with no final event |
# A reply of exactly 1,000 input and 2,000 output tokens, to test what that costs a wallet.
curl https://api.hixel.dev/v1/chat/completions \
-H "Authorization: Bearer $HIXEL_API_KEY" \
-H "Content-Type: application/json" \
-H "x-hixel-customer: org_42" \
-H "x-hixel-mock: tokens=1000:2000,text=Hello%2C world" \
-d '{ "model": "claude-sonnet-5-5", "messages": [{ "role": "user", "content": "Hi" }] }'# The provider is overloaded: test your retry path.
-H "x-hixel-mock: status=529"A header the mock cannot read is refused with 400 and invalid_mock_directive before anything
is reserved. In Production the header is ignored. It is never sent to a provider.
Some requests have nothing the mock could answer with, such as an image as a URL or an audio
format other than MP3, WAV or PCM; they are refused with unsupported_in_test_mode naming the
field.
Moving to Production#
- Create a key in Production. It starts with
hx_sk_and calls real providers. - Recreate what your test environment had: customers are per environment, and so are wallets, webhook endpoints, the Stripe connection and settings.
- Production's Stripe connection takes only a live Stripe key, and test environments only a test key, so a test payment can never credit a live wallet.