GatewayDocsOpen workspace ↗
Developer preview · Synthetic data only Launch status ↗
Documentation/Get started

Your first request

Make your first request with a free sandbox key, then switch to a production model.

1. Create a sandbox key

  1. Sign in to your Gateway workspace.
  2. In Set up your gateway, choose Create a sandbox key. Sandbox keys start with gw_sandbox_ and need no agreement, credits or card.
  3. Copy the key when it is shown. It is displayed once and stored only as a hash.

2. Configure your environment

Set GATEWAY_API_KEY in your shell or secret manager to the key you just created. The base URL is:

shell
export GATEWAY_BASE_URL='https://gateway.accountablehq.com'

Use a server-side environment variable. Do not place the key in client-side JavaScript, a mobile app bundle, source control, screenshots, or URLs. Gateway is currently an invitation-only preview; your workspace administrator provides access.

3. Save request.json and send it

json
{
  "model": "sandbox-chat",
  "messages": [
    {
      "role": "user",
      "content": "Explain an AI gateway in one sentence."
    }
  ],
  "max_tokens": 64
}
shell
curl "$GATEWAY_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $GATEWAY_API_KEY" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: quickstart-001' \
  --data-binary @request.json

Use a new idempotency key for each new logical request. To call a real model later, create a production key (after your organization signs the agreements and adds credits), call GET /v1/models, and replace sandbox-chat with a returned alias such as gpt-6-luna.

4. Check the result

A successful request returns 200, an assistant message in choices[0].message.content, token usage, and a gateway object with the request ID and charge. Sandbox answers are simulated and always cost $0.00.

Open Activity to see metadata for the request. The gateway does not retain the answer for later replay.

Use the official OpenAI SDK

javascript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://gateway.accountablehq.com/v1',
  apiKey: process.env.GATEWAY_API_KEY,
  maxRetries: 0, // retry deliberately with an Idempotency-Key instead
});

const completion = await client.chat.completions.create(
  {
    model: 'sandbox-chat', // later: a production alias such as 'gpt-6-luna'
    messages: [{ role: 'user', content: 'Explain an AI gateway in one sentence.' }],
    max_tokens: 64,
  },
  { headers: { 'Idempotency-Key': crypto.randomUUID() } },
);
console.log(completion.choices[0].message.content);
python
import os
import uuid
from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.accountablehq.com/v1",
    api_key=os.environ["GATEWAY_API_KEY"],
    max_retries=0,  # retry deliberately with an Idempotency-Key instead
)

completion = client.chat.completions.create(
    model="sandbox-chat",  # later: a production alias such as "gpt-6-luna"
    messages=[{"role": "user", "content": "Explain an AI gateway in one sentence."}],
    max_tokens=64,
    extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)
print(completion.choices[0].message.content)

Automatic SDK retries are turned off on purpose. A timeout does not prove the model did not run, so a blind retry can be billed twice. Retry only with the same Idempotency-Key; the gateway refuses a duplicate while the first attempt is pending or succeeded, and accepts the same key again after a failure that cost nothing. See idempotency.

If the request fails

  • 401: confirm the key belongs to this environment and has not been revoked.
  • 429: slow down. Production keys allow 30 requests per minute; sandbox keys 10.
  • 402: add credits or reduce max_tokens so the maximum reservation fits the budget (production keys only; sandbox requests are free).
  • 403: check model permissions. Sandbox keys can call only sandbox-chat; production keys cannot call it.
  • 409 on a second run: the idempotency key has already been used; this is expected.
  • 502 with an unknown outcome: do not automatically submit a new request. Read retry guidance.

Search documentation

Search all 25 guides and references.