# Use GLM-5.3-Flash & gpt-oss-120b on BharatRouter

Instructions for an AI coding agent to configure any OpenAI-compatible tool (or the user's own code)
to use BharatRouter's models. BharatRouter is OpenAI-wire compatible.

## Endpoint
- Base URL: `https://api.bharatrouter.com/v1`
- Auth header: `Authorization: Bearer br-XXXXXXXX`  (the user's BharatRouter key; get one at https://bharatrouter.com/console#keys)
- Models (pass as the OpenAI `model` field):
  - `glm-5.3-flash` — fast, 1M-token context; iteration, whole-repo prompts, high-volume chat.
  - `gpt-oss-120b` — heavier agentic coding, long tool-loops.
- Streaming and tool-calling are supported.

## curl
```
curl https://api.bharatrouter.com/v1/chat/completions \
  -H "Authorization: Bearer br-XXXXXXXX" -H "Content-Type: application/json" \
  -d '{"model":"glm-5.3-flash","messages":[{"role":"user","content":"Refactor this and explain why."}]}'
```

## Python (OpenAI SDK)
```python
from openai import OpenAI
client = OpenAI(base_url="https://api.bharatrouter.com/v1", api_key="br-XXXXXXXX")
resp = client.chat.completions.create(
    model="glm-5.3-flash",   # or gpt-oss-120b
    messages=[{"role": "user", "content": "Write a FastAPI healthcheck endpoint."}],
    stream=True,
)
for chunk in resp:
    print(chunk.choices[0].delta.content or "", end="", flush=True)
```

## Node (openai package)
```js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.bharatrouter.com/v1", apiKey: "br-XXXXXXXX" });
const r = await client.chat.completions.create({
  model: "glm-5.3-flash",
  messages: [{ role: "user", content: "Explain this stack trace." }],
});
console.log(r.choices[0].message.content);
```

## Coding agents
- **brcode:** `brcode login && brcode init` then `brcode model glm-5.3-flash` (or `gpt-oss-120b`), then `brcode`.
- **Codex CLI:** point it at `https://api.bharatrouter.com/v1` (Responses API) with the `br-` key.
- **Hermes:** see https://bharatrouter.com/blog/hermes-agent-bharatrouter.md

## Notes
- Keep the `br-` key in an env var; never commit it.
- No silent fallback: an unrouted model id returns an OpenAI-style 4xx — fix the `model` value.
- Metered on the key; budgets at https://bharatrouter.com/console#spend

Human-readable version: https://bharatrouter.com/blog/glm-flash-coding-agent
