# Plugging the key into tools

Everywhere: base URL `https://api.brrrain.fun/v1`, API key `brrr_…` (keep it in an environment
variable or the tool's secret store), model id from `GET https://api.brrrain.fun/v1/models`.
The examples use `z-ai/glm-5.3-flash`; use any listed id.

## OpenAI SDK (Python)

```python
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.brrrain.fun/v1", api_key=os.environ["BRRRAIN_API_KEY"])
reply = client.chat.completions.create(model="z-ai/glm-5.3-flash", max_tokens=500,
                                       messages=[{"role": "user", "content": "Hello"}])
print(reply.choices[0].message.content)
```

Errors arrive as `openai.APIStatusError`; `e.body["error"]["code"]` is our
code (`quota_exhausted`, …) and `e.response.headers` has `Retry-After`. The
SDK retries 429 and 5xx by itself (twice by default), which suits
`rate_limited` and `upstream_unavailable`; `quota_exhausted` and
`max_tokens_too_high` are 402 and are not retried.

## OpenAI SDK (JavaScript / TypeScript)

```js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.brrrain.fun/v1", apiKey: process.env.BRRRAIN_API_KEY });
const reply = await client.chat.completions.create({ model: "z-ai/glm-5.3-flash", max_tokens: 500,
  messages: [{ role: "user", content: "Hello" }] });
```

## LangChain (Python)

```python
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(base_url="https://api.brrrain.fun/v1", api_key=os.environ["BRRRAIN_API_KEY"],
                 model="z-ai/glm-5.3-flash", max_tokens=500)
```

## Vercel AI SDK (version 5)

```ts
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const brrrain = createOpenAICompatible({ name: "brrrain", baseURL: "https://api.brrrain.fun/v1", apiKey: process.env.BRRRAIN_API_KEY });
const { text } = await generateText({ model: brrrain("z-ai/glm-5.3-flash"), maxOutputTokens: 500, prompt: "Hello" });
```

## Editors and coding agents

| Tool | Where | What to set |
|---|---|---|
| Continue | `config.yaml` → `models` | `provider: openai`, `apiBase: https://api.brrrain.fun/v1`, `apiKey`, `model: <id>` |
| Cline | Settings → API Provider → OpenAI Compatible | Base URL `https://api.brrrain.fun/v1`, API Key, Model ID |
| Aider | environment | `OPENAI_API_BASE=https://api.brrrain.fun/v1`, `OPENAI_API_KEY=brrr_…`, then `aider --model openai/<id>` |
| Cursor | Settings → Models | OpenAI API Key = the key, "Override OpenAI Base URL" = `https://api.brrrain.fun/v1`, add the model id as a custom model |

Coding agents send long contexts many times: watch Power with a cheap model
first, and give the tool its own key with a daily cap.
