# Use the Claude Agent SDK with GLM-5.3 (pay per token)

The Claude Agent SDK runs Claude Code underneath, so it takes the same variables. Pass them in `env` to point it at InferSpeed's Anthropic-compatible endpoint and set the model to `glm-5.3`. You pay per token from a prepaid balance.

Last checked: 2026-10-18 (the date the site verified this config) · @anthropic-ai/claude-agent-sdk 0.3.302 · claude-agent-sdk 0.2.168 (Python)

## Setup

The variables go in `env`: they are not read from `~/.claude/settings.json` unless you load settings.

TypeScript (`npm i @anthropic-ai/claude-agent-sdk`):

```typescript
import { query } from "@anthropic-ai/claude-agent-sdk";

const model = "glm-5.3";
for await (const msg of query({
  prompt: "List the files in this directory.",
  options: {
    env: {
      ...process.env,
      ANTHROPIC_BASE_URL: "https://api.inferspeed.ai",
      ANTHROPIC_AUTH_TOKEN: process.env.INFERSPEED_API_KEY,
      ANTHROPIC_MODEL: model,
      ANTHROPIC_DEFAULT_OPUS_MODEL: model,
      ANTHROPIC_DEFAULT_SONNET_MODEL: model,
      ANTHROPIC_DEFAULT_HAIKU_MODEL: model,
      ANTHROPIC_DEFAULT_FABLE_MODEL: model,
      CLAUDE_CODE_SUBAGENT_MODEL: model,
      CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
    },
  },
})) {
  if (msg.type === "result") console.log(msg.result);
}
```

Python (`pip install claude-agent-sdk`):

```python
import asyncio, os
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, query

model = "glm-5.3"
env = {
    "ANTHROPIC_BASE_URL": "https://api.inferspeed.ai",
    "ANTHROPIC_AUTH_TOKEN": os.environ["INFERSPEED_API_KEY"],
    "ANTHROPIC_MODEL": model,
    "ANTHROPIC_DEFAULT_OPUS_MODEL": model,
    "ANTHROPIC_DEFAULT_SONNET_MODEL": model,
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": model,
    "ANTHROPIC_DEFAULT_FABLE_MODEL": model,
    "CLAUDE_CODE_SUBAGENT_MODEL": model,
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
}

async def main():
    async for msg in query(prompt="List the files in this directory.", options=ClaudeAgentOptions(env=env)):
        if isinstance(msg, ResultMessage):
            print(msg.result)

asyncio.run(main())
```

Create a key at https://inferspeed.ai/keys and export it as `INFERSPEED_API_KEY`. Keep `glm-5.3` (not `glm-5.3-flash`) in every model variable: `glm-5.3-flash` is served on `/v1/chat/completions` only, and the SDK uses the Anthropic Messages endpoint.

## What works

Tool calls (built-in tools and your own MCP tools), streaming, `count_tokens` and the `anthropic-beta` headers the SDK sends all work. Verified on 2026-10-18 with `@anthropic-ai/claude-agent-sdk` 0.3.302 and `claude-agent-sdk` 0.2.168 (Python), each running a query that calls an MCP tool.

## Model names and routing

- Keep the model variables. Without them the SDK asks for its default `claude-*` names; on InferSpeed those are routed to `glm-5.3` (`kimi-k3` on a Kimi key), and you are billed at the price of the model that served the request.
- The response says which model served it: the `model` field and the `X-Served-Model` header. The name you sent is in `X-Model-Routed-From`.
- Want an error instead of routing? Send `X-Model-Strict: 1`: an unavailable model then returns 404 `model_coming_soon` or `model_not_found`, or 400 `model_not_available`.

## Price (USD per 1M tokens)

| Model | Input | Output | Cache read | Vendor list price (in / out) |
|---|---|---|---|---|
| glm-5.3 | $0.84 | $2.64 | $0.156 | $1.40 / $4.40 |
| kimi-k3 | $1.80 | $9.00 | $0.18 | $3.00 / $15.00 |

Live prices for every model: https://inferspeed.ai/model-plaza

## Where the model comes from

glm-5.3 is published by Z.ai. It is served from the vendor's published model through more than one route; a route may run the vendor's FP8 weights on our own hardware. Vendor-reported scores and our own measurement method: https://inferspeed.ai/benchmarks.md

## Limits

- One key calls every live model (`glm-5.3`, `kimi-k3`, ...): name the model in the request. Each request is billed at the price of the model that served it.
- New accounts: 30 requests per minute and 5 concurrent requests, across all keys of the account.

## FAQ

**How do I check what I was charged?**
Call `GET https://api.inferspeed.ai/v1/usage` with your key: it returns today's and total tokens and `actual_cost`. How we check billing (charged amount equals billed tokens × published price) and how to run that check yourself: https://inferspeed.ai/benchmarks.md

We run InferSpeed.
