# Bzanes AI API

Bzanes AI gives you one API key and one prepaid balance for hundreds of AI models: chat (Claude, GPT, Gemini, DeepSeek, MiMo, GLM, Qwen, Grok, Kimi…), web search models, image models and video models.

- Base URL: `https://api.bzanes.com/v1`
- Auth header: `Authorization: Bearer bz_live_...`
- Chat is **OpenAI-compatible**. Any code that uses the OpenAI SDK or OpenRouter works by changing two values: the base URL and the key.
- Pricing: pay as you go from your Bzanes balance. Live prices per model: https://bzanes.com/ai/models (JSON: `GET /v1/models`).

## 1. Get an API key (for humans, or tell your human to do this)
1. Sign in at https://bzanes.com/login (email code, Google, or password).
2. Open https://bzanes.com/dashboard/ai
3. Top up your balance (minimum $10, card or USDT). Turn on **Auto top-up** so your app never stops (recommended: top up $20 when balance is below $5).
4. Under **API keys**, type a name (for example "My store") and press **Create key**. Copy the key (`bz_live_...`). It is shown once.
5. Optional: set a spending limit per key.

## 2. Chat completions
```bash
curl https://api.bzanes.com/v1/chat/completions \
  -H "Authorization: Bearer $BZANES_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"xiaomi/mimo-v2.6-pro","messages":[{"role":"user","content":"Hello"}]}'
```

JavaScript (OpenAI SDK):
```js
import OpenAI from "openai";
const ai = new OpenAI({ baseURL: "https://api.bzanes.com/v1", apiKey: process.env.BZANES_API_KEY });
const r = await ai.chat.completions.create({ model: "deepseek/deepseek-v4.1-flash", messages: [{ role: "user", content: "Hi" }] });
```

Python:
```python
from openai import OpenAI
ai = OpenAI(base_url="https://api.bzanes.com/v1", api_key=os.environ["BZANES_API_KEY"])
r = ai.chat.completions.create(model="anthropic/claude-sonnet-5.5", messages=[{"role":"user","content":"Hi"}])
```

Streaming (`"stream": true`), tools/function calling, JSON mode and vision inputs work the same as OpenAI/OpenRouter.

**Search models:** use a search model id (tab "Search" on the models page), or append `:online` to a chat model id where listed.

## 3. Images and video
Queue based (submit, then poll):
```bash
# submit
curl -X POST https://api.bzanes.com/v1/media/fal-ai/flux/schnell \
  -H "Authorization: Bearer $BZANES_API_KEY" -H "Content-Type: application/json" \
  -d '{"prompt":"a cozy coffee shop logo, flat"}'
# -> {"request_id":"...","status":"IN_QUEUE","cost_usd":0.004,"status_url":"...","result_url":"..."}

# poll status, then fetch the result
curl https://api.bzanes.com/v1/media/requests/<request_id> -H "Authorization: Bearer $BZANES_API_KEY"
curl https://api.bzanes.com/v1/media/requests/<request_id>/result -H "Authorization: Bearer $BZANES_API_KEY"
```
The model id is the path after `/v1/media/` (see tabs "Images" and "Video" on the models page). The request body is the model's normal input (prompt, image_url, duration, num_images…). Image and video requests are charged when submitted.

## 4. Switching an existing project
**From OpenRouter:** set base URL `https://openrouter.ai/api/v1` → `https://api.bzanes.com/v1` and `OPENROUTER_API_KEY` → your `bz_live_` key. Model ids are the same.

**From OpenAI:** set `baseURL` to `https://api.bzanes.com/v1`, use your Bzanes key, and prefix models (`gpt-5.6-terra` → `openai/gpt-5.6-terra`).

**From fal.ai:** replace `https://queue.fal.run/<model>` with `https://api.bzanes.com/v1/media/<model>` and the header `Authorization: Key <FAL_KEY>` with `Authorization: Bearer <bz_live_key>`. Poll `/v1/media/requests/<id>` and `/result` instead of fal's status/response URLs.

Projects installed by Bzanes can be switched to Bzanes AI during installation: we put your key in the env var `BZANES_API_KEY` and point the project's AI base URL to Bzanes. You can also do it yourself with the steps above.

## 5. Send emails to your project's users
For domains bought on Bzanes. Enable sending at https://bzanes.com/dashboard/email, then:
```bash
curl https://api.bzanes.com/v1/email/send \
  -H "Authorization: Bearer $BZANES_API_KEY" -H "Content-Type: application/json" \
  -d '{"from":"hello@yourdomain.com","to":"user@example.com","subject":"Welcome","html":"<p>Hi!</p>","text":"Hi!"}'
```
Free: 50 emails per day and 1,500 per month per domain (no rollover). After that, email packs: 1,000 emails for $0.70, valid 12 months. `to` can be a list (max 50).

## 6. Other endpoints
- `GET /v1/models` – all models with live prices (no key needed).
- `GET /v1/balance` – your balance and this key's spend.

## Errors
- `401 invalid_api_key` – missing or revoked key.
- `402 insufficient_balance` – top up at https://bzanes.com/dashboard/ai (or enable auto top-up).
- `402 key_limit` – this key reached its spending limit.
- `404 model_not_found` – check the id on https://bzanes.com/ai/models.

## Notes for AI agents
- Store the key in an environment variable named `BZANES_API_KEY`. Never hardcode it in client-side code.
- Prefer cheap, strong models for bulk tasks: `xiaomi/mimo-v2.6-pro`, `deepseek/deepseek-v4.1-flash`, `z-ai/glm-5.3-flash`, `qwen/qwen3.8-flash`.
- If you get `402`, ask your human to top up or enable auto top-up at https://bzanes.com/dashboard/ai.
