# Inference API

> Call models on the devnet inference gateway through its OpenAI- and Anthropic-compatible APIs, from your own code or from a sandbox.

Source: https://docs.compute.dev.ddcdragon.com/guides/inference/

The inference gateway, `https://inference-gateway.compute.dev.ddcdragon.com`, serves models through an
OpenAI-compatible API at `/openai/v1` and an Anthropic-compatible API at `/anthropic`. Point an OpenAI or Anthropic
client at it with a key for your bucket; the calls are billed to that bucket.

## Get a key

The key is a COMPUTE token for your bucket, the same kind of token the `cere` CLI signs in with. Create one in the
Developer Console:

- **Inference** > **API keys** > **Create key**: 7, 30 or 90 days;
- **Access tokens** > **A token for CI**: 1, 7 or 30 days.

Either is shown once, cannot be revoked, and lets whoever holds it spend from your bucket until it expires. The
examples on this page read it from `CERE_TOKEN`:

```sh
export CERE_TOKEN="$(cat token.txt)"
```

## List models

`GET /openai/v1/models` lists the models you can call (`GET /anthropic/v1/models` lists the same in Anthropic's
shape). Each has an id, `<bucket>/<name>/<version>`, and an alias; a request names either. The examples on this page
use `glm-5.3`.

**curl**

```sh
curl -s https://inference-gateway.compute.dev.ddcdragon.com/openai/v1/models \
  -H "Authorization: Bearer $CERE_TOKEN"
```

```
{"object":"list","data":[{"id":"1338/emotion-english-distilroberta-base/v1.0.2","object":"model","created":0,"owned_by":"ddc","alias":"emotion-english-distilroberta-base"},{"id":"1338/gemma4_31b/v1.0.0","object":"model","created":0,"owned_by":"ddc","alias":"gemma4_31b"},{"id":"1338/glm-5.3/v1.0.0","object":"model","created":0,"owned_by":"ddc","alias":"glm-5.3"},...]}
```

**Python**

```python
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://inference-gateway.compute.dev.ddcdragon.com/openai/v1",
    api_key=os.environ["CERE_TOKEN"],
)
for model in client.models.list():
    print(model.id)
```

```
1338/emotion-english-distilroberta-base/v1.0.2
1338/gemma4_31b/v1.0.0
1338/glm-5.3/v1.0.0
1338/glm-5.3-flash/v1.0.0
1338/parakeet-tdt-0.6b-v2/v1.0.0
1338/parakeet-tdt-0.6b-v3/v1.0.0
1338/pyannote-segmentation-3.0/v1.3.2
1338/qwen3-embedding-4b/v1.0.0
1338/qwen38_27b/v1.0.4
1338/ser-odyssey-wavlm/v1.1.0
1338/titanet-large/v1.0.0
1338/wavlm-authenticity/v0.1.0
```

**JavaScript**

```js
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://inference-gateway.compute.dev.ddcdragon.com/openai/v1',
  apiKey: process.env.CERE_TOKEN,
});
for await (const model of client.models.list()) {
  console.log(model.id);
}
```

```
1338/emotion-english-distilroberta-base/v1.0.2
1338/gemma4_31b/v1.0.0
1338/glm-5.3/v1.0.0
1338/glm-5.3-flash/v1.0.0
1338/parakeet-tdt-0.6b-v2/v1.0.0
1338/parakeet-tdt-0.6b-v3/v1.0.0
1338/pyannote-segmentation-3.0/v1.3.2
1338/qwen3-embedding-4b/v1.0.0
1338/qwen38_27b/v1.0.4
1338/ser-odyssey-wavlm/v1.1.0
1338/titanet-large/v1.0.0
1338/wavlm-authenticity/v0.1.0
```

## Chat completions (OpenAI-compatible)

`POST /openai/v1/chat/completions` takes an OpenAI chat request. With the `openai` package (`pip install openai`,
`npm install openai`), the base URL ends in `/openai/v1`.

**curl**

```sh
curl -s https://inference-gateway.compute.dev.ddcdragon.com/openai/v1/chat/completions \
  -H "Authorization: Bearer $CERE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "glm-5.3", "messages": [{"role": "user", "content": "Say hello in five words."}]}'
```

```
{"id":"chatcmpl-37952d89142b5ff9471c1c9b","object":"chat.completion","created":1795623171,"model":"glm-5.3","choices":[{"index":0,"message":{"role":"assistant","content":"Hello, nice to see you!","reasoning_content":"The user wants me to say hello in exactly five words. ..."},"finish_reason":"stop"}],"usage":{"prompt_tokens":18,"completion_tokens":308,"total_tokens":326}}
```

**Python**

```python
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://inference-gateway.compute.dev.ddcdragon.com/openai/v1",
    api_key=os.environ["CERE_TOKEN"],
)
reply = client.chat.completions.create(
    model="glm-5.3",
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(reply.choices[0].message.content)
print(reply.usage.prompt_tokens, reply.usage.completion_tokens)
```

```
Hello there, my dear friend!
18 274
```

**JavaScript**

```js
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://inference-gateway.compute.dev.ddcdragon.com/openai/v1',
  apiKey: process.env.CERE_TOKEN,
});
const reply = await client.chat.completions.create({
  model: 'glm-5.3',
  messages: [{ role: 'user', content: 'Say hello in five words.' }],
});
console.log(reply.choices[0].message.content);
console.log(reply.usage.prompt_tokens, reply.usage.completion_tokens);
```

```
Hello there, wonderful human being!
18 628
```

:::note
`glm-5.3` reasons before it answers. The reasoning comes back as `reasoning_content` in the OpenAI API and as a
`thinking` block before the text in the Anthropic API, and its tokens count as output tokens: a five-word answer above
used hundreds.
:::

## Messages (Anthropic-compatible)

`POST /anthropic/v1/messages` takes an Anthropic Messages request. With the `anthropic` package
(`pip install anthropic`, `npm install @anthropic-ai/sdk`), the base URL ends in `/anthropic`: the client adds
`/v1/messages` itself.

**curl**

```sh
curl -s https://inference-gateway.compute.dev.ddcdragon.com/anthropic/v1/messages \
  -H "Authorization: Bearer $CERE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "glm-5.3", "max_tokens": 256, "messages": [{"role": "user", "content": "Say hello in five words."}]}'
```

```
{"id":"msg_f1ad701c930a68e823986bf8","type":"message","role":"assistant","model":"glm-5.3","content":[{"type":"thinking","thinking":"The user wants me to say hello in exactly five words. ...","signature":""},{"type":"text","text":"Hello, how are you today?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":18,"output_tokens":228,"cache_creation_input_tokens":0,"cache_read_input_tokens":0}}
```

**Python**

```python
import os

from anthropic import Anthropic

client = Anthropic(
    base_url="https://inference-gateway.compute.dev.ddcdragon.com/anthropic",
    api_key=os.environ["CERE_TOKEN"],
)
msg = client.messages.create(
    model="glm-5.3",
    max_tokens=256,
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(msg.content[-1].text)
print(msg.usage.input_tokens, msg.usage.output_tokens)
```

```
Hello there, how are you?
18 168
```

**JavaScript**

```js
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  baseURL: 'https://inference-gateway.compute.dev.ddcdragon.com/anthropic',
  apiKey: process.env.CERE_TOKEN,
});
const msg = await client.messages.create({
  model: 'glm-5.3',
  max_tokens: 256,
  messages: [{ role: 'user', content: 'Say hello in five words.' }],
});
console.log(msg.content.at(-1).text);
console.log(msg.usage.input_tokens, msg.usage.output_tokens);
```

```
Hello, how are you today?
18 250
```

## Stream the response

Set `"stream": true` (or use the client's streaming call) to get the answer as server-sent events while the model
writes it.

**curl**

```sh
curl -sN https://inference-gateway.compute.dev.ddcdragon.com/openai/v1/chat/completions \
  -H "Authorization: Bearer $CERE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "glm-5.3", "stream": true, "messages": [{"role": "user", "content": "Count from 1 to 5."}]}'
```

```
data: {"id":"chatcmpl-d755a83a39f3c145838edb58","object":"chat.completion.chunk","created":1795623273,"model":"glm-5.3","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

data: {"id":"chatcmpl-d755a83a39f3c145838edb58","object":"chat.completion.chunk","created":1795623273,"model":"glm-5.3","choices":[{"index":0,"delta":{"reasoning_content":"The"},"finish_reason":null}]}

...

data: {"id":"chatcmpl-d755a83a39f3c145838edb58","object":"chat.completion.chunk","created":1795623273,"model":"glm-5.3","choices":[{"index":0,"delta":{"content":"1, 2,"},"finish_reason":null}]}

...

data: {"id":"chatcmpl-d755a83a39f3c145838edb58","object":"chat.completion.chunk","created":1795623273,"model":"glm-5.3","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":20,"completion_tokens":44,"total_tokens":64}}

data: [DONE]
```

**Python**

```python
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://inference-gateway.compute.dev.ddcdragon.com/openai/v1",
    api_key=os.environ["CERE_TOKEN"],
)
stream = client.chat.completions.create(
    model="glm-5.3",
    messages=[{"role": "user", "content": "Count from 1 to 5."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()
```

```
1, 2, 3, 4, 5.
```

**JavaScript**

```js
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://inference-gateway.compute.dev.ddcdragon.com/openai/v1',
  apiKey: process.env.CERE_TOKEN,
});
const stream = await client.chat.completions.create({
  model: 'glm-5.3',
  messages: [{ role: 'user', content: 'Count from 1 to 5.' }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
process.stdout.write('\n');
```

```
1, 2, 3, 4, 5.
```

The Anthropic API streams with `"stream": true` too, as Anthropic's events:

**curl**

```sh
curl -sN https://inference-gateway.compute.dev.ddcdragon.com/anthropic/v1/messages \
  -H "Authorization: Bearer $CERE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "glm-5.3", "max_tokens": 256, "stream": true, "messages": [{"role": "user", "content": "Count from 1 to 5."}]}'
```

```
event: message_start
data: {"type":"message_start","message":{"id":"msg_b9f3e0dedf27c45d05c7bd7b","type":"message","role":"assistant","model":"glm-5.3","content":[],...}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"thinking","signature":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":"The"}}

...

event: content_block_delta
data: {"type":"content_block_delta","index":1,"delta":{"type":"text_delta","text":"1, 2"}}

...

event: message_stop
data: {"type":"message_stop"}
```

**Python**

```python
import os

from anthropic import Anthropic

client = Anthropic(
    base_url="https://inference-gateway.compute.dev.ddcdragon.com/anthropic",
    api_key=os.environ["CERE_TOKEN"],
)
stream = client.messages.create(
    model="glm-5.3",
    max_tokens=256,
    messages=[{"role": "user", "content": "Count from 1 to 5."}],
    stream=True,
)
for event in stream:
    if event.type == "content_block_delta" and event.delta.type == "text_delta":
        print(event.delta.text, end="", flush=True)
print()
```

```
1, 2, 3, 4, 5
```

**JavaScript**

```js
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  baseURL: 'https://inference-gateway.compute.dev.ddcdragon.com/anthropic',
  apiKey: process.env.CERE_TOKEN,
});
const stream = client.messages.stream({
  model: 'glm-5.3',
  max_tokens: 256,
  messages: [{ role: 'user', content: 'Count from 1 to 5.' }],
});
stream.on('text', (text) => process.stdout.write(text));
await stream.finalMessage();
process.stdout.write('\n');
```

```
1, 2, 3, 4, 5
```

:::caution
In Python, stream with `messages.create(..., stream=True)` as above. The `anthropic` package's `messages.stream()`
helper fails on this gateway's thinking blocks (`TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'`).
:::

## Call a model from a sandbox

A sandbox reaches the gateway through the egress proxy, which adds your key to its requests; the sandbox holds only a
placeholder. Store your login token as a secret bound to the gateway's host, once:

```sh
cere secret set ddc-inference --from-login
```

```
Stored secret ddc-inference (header Authorization): your login token for bucket <bucket-id>, sent only to inference-gateway.compute.dev.ddcdragon.com.
It stops working when that token expires, 2026-12-24T21:57:01Z (in 29d05h); after your next cere login, run this again.
```

Then allow the gateway with that secret, and call it with any key: the proxy replaces the `Authorization` header.
This script uses only Python's standard library:

```python title="call_model.py"
import json
import urllib.request

req = urllib.request.Request(
    "https://inference-gateway.compute.dev.ddcdragon.com/openai/v1/chat/completions",
    data=json.dumps({
        "model": "glm-5.3",
        "messages": [{"role": "user", "content": "Say hello in five words."}],
    }).encode(),
    headers={"Authorization": "Bearer placeholder", "Content-Type": "application/json"},
)
with urllib.request.urlopen(req, timeout=120) as r:
    print(json.load(r)["choices"][0]["message"]["content"])
```

**CLI**

```sh
ID=$(cere sandbox create --image python:3.12-slim --timeout 300 -q \
  --allow inference-gateway.compute.dev.ddcdragon.com:POST:/openai/v1:ddc-inference)
cere sandbox exec $ID --stdin -- python - < call_model.py
cere egress log --sandbox $ID
cere sandbox terminate $ID
```

```
Hello, how are you today?
TIME                  SANDBOX                        DECISION  METHOD  HOST                                         PATH                         STATUS  CREDENTIAL     DOWN   MS    REASON
2026-11-25T16:20:10Z  sb-01m89r3p4fy9313273mw9y3s8e  allowed   POST    inference-gateway.compute.dev.ddcdragon.com  /openai/v1/chat/completions  200     ddc-inference  836 B  2550  -
sb-01m89r3p4fy9313273mw9y3s8e terminated: terminated by API
...
```

The egress log can take a few seconds to show a request.

**Python**

```python
import cere

sb = cere.Sandbox.create(
    image="python:3.12-slim",
    timeout=300,
    egress=[cere.Allow("inference-gateway.compute.dev.ddcdragon.com", ["POST"], "/openai/v1", "ddc-inference")],
)
p = sb.exec("python", "-c", open("call_model.py").read())
print(p.stdout.read(), end="")
sb.terminate()
```

```
Hello there, how are you?
```

The agents in [Agents](https://docs.compute.dev.ddcdragon.com/guides/agents/) reach their model the same way. For egress rules and secrets in general, see
[Egress and secrets](https://docs.compute.dev.ddcdragon.com/guides/egress-and-secrets/).

## Limits and errors

Your bucket may have 8 requests in flight on each model at once. `GET /api/v1/limits` shows your bucket's limit on
each model, how many of its requests are in flight now, and the model's own capacity:

```sh
curl -s https://inference-gateway.compute.dev.ddcdragon.com/api/v1/limits -H "Authorization: Bearer $CERE_TOKEN"
```

```
{"bucket":<bucket-id>,"profile":"default","scope":"cluster","enabled":true,"models":[...,{"model":"1338/glm-5.3/v1.0.0","alias":"glm-5.3","limit":{"maxInFlight":8},"inFlight":3,"modelStatus":{"status":"available","ceiling":16,"inFlight":3}},...]}
```

A request over the limit is refused at once; it does not wait. Errors come in the envelope of the API you called,
with the types the OpenAI and Anthropic clients recognise:

| Status | OpenAI `type` (`code`) | Anthropic `type` | Meaning |
|---|---|---|---|
| 401 | `invalid_request_error` (`invalid_api_key`) | `authentication_error` | The key is missing, malformed or expired. |
| 403 | `invalid_request_error` (`insufficient_permissions`) | `permission_error` | The key does not grant COMPUTE on a bucket its signer owns, or the bucket's owner has no balance left. |
| 404 | `invalid_request_error` (`model_not_found`) | `not_found_error` | No node serves the model now: a wrong name, or a model that is briefly unavailable. |
| 429 | `rate_limit_error` (`rate_limit_exceeded`) | `rate_limit_error` | Your bucket has 8 requests in flight on the model, or the model is at capacity. Wait, or send fewer at once. |
| 502 | `server_error` (`upstream_error`) | `api_error` | A service behind the model failed. Retry. |
| 503 | `server_error` (`overloaded` or `service_unavailable`) | `api_error` | The model is saturated right now, or has no capacity. Retry with backoff. |
| 529 | | `overloaded_error` | The Anthropic API's status for a saturated model. Retry with backoff. |
| 504 | `server_error` (`timeout`) | `timeout_error` | The inference ran out of time. |

A refusal carries a `Retry-After` header when the gateway can tell how long to wait. For example:

```sh
curl -s https://inference-gateway.compute.dev.ddcdragon.com/openai/v1/chat/completions \
  -H "Authorization: Bearer not-a-token" \
  -H "Content-Type: application/json" \
  -d '{"model": "glm-5.3", "messages": [{"role": "user", "content": "hi"}]}'
```

```
{"error":{"code":"invalid_api_key","message":"malformed auth token","param":null,"type":"invalid_request_error"}}
```

and a saturated model on the Anthropic API (status 529):

```
{"type":"error","error":{"type":"overloaded_error","message":"inference failed: remote: no account can serve glm-5.3 right now"},"request_id":"69153fdf-ab78-4266-9a00-b52dc96a4117"}
```

## Cost

Model calls are billed to the bucket the key belongs to, at the model's price per million input and output tokens.
Developer Console > **Inference** > **Models** shows each model's price and your balance, and **Usage** shows what
your bucket used.

## Related

- [Next: Signing in](https://docs.compute.dev.ddcdragon.com/guides/signing-in/)
- [Agents](https://docs.compute.dev.ddcdragon.com/guides/agents/)
- [Egress and secrets](https://docs.compute.dev.ddcdragon.com/guides/egress-and-secrets/)
- [Resources and billing](https://docs.compute.dev.ddcdragon.com/concepts/resources-and-billing/)
- [Clusters and endpoints](https://docs.compute.dev.ddcdragon.com/reference/clusters/)
