# Stewerd API docs

> One OpenAI-compatible API key for DeepSeek, Qwen, Kimi, GLM, MiniMax and more, plus an MCP endpoint. Credit is required; there is no free tier.

HTML version: https://stewerd.com/docs

## Quickstart

Keep the OpenAI SDK. Change the base URL and use a Stewerd key.

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.stewerd.com/v1",
    api_key="ql_live_...",
)

resp = client.chat.completions.create(
    model="deepseek-v4.1-flash",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
```

```bash
curl https://api.stewerd.com/v1/chat/completions \
  -H "Authorization: Bearer $STEWERD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"deepseek-v4.1-flash",
       "messages":[{"role":"user","content":"Hello!"}]}'
```

## Models (USD per million tokens)

| Model id | Provider | Input | Output |
|---|---|---|---|
| deepseek-v4-flash | deepseek | $0.1866 | $0.3731 |
| deepseek-v4-flash-0731 | deepseek | $0.1866 | $0.7463 |
| deepseek-v4-pro-0813 | deepseek | $0.9595 | $2.878 |
| deepseek-v4.1-flash | deepseek | $0.1863 | $0.7452 |
| doubao-seed-2-0-lite-260428 | bytedance | $0.1279 | $0.7676 |
| doubao-seed-2-0-mini-260428 | bytedance | $0.04264 | $0.38 |
| doubao-seed-2-0-pro-260215 | bytedance | $0.6823 | $3.412 |
| doubao-seed-2.1-pro | bytedance | $1.279 | $6.397 |
| glm-5 | zhipu | $0.8529 | $3.358 |
| glm-5-turbo | zhipu | $1.066 | $4.104 |
| glm-5.1 | zhipu | $1.279 | $4.478 |
| glm-5.2 | zhipu | $1.706 | $5.97 |
| glm-5.3 | zhipu | $1.706 | $5.224 |
| glm-5.3-flash | zhipu | $0.1493 | $0.5224 |
| glm-5v-turbo | zhipu | $1.066 | $4.104 |
| hy3 | tencent | $0.1866 | $0.7463 |
| hy3-preview | tencent | $0.2559 | $0.8529 |
| kimi-k2.5 | moonshot | $0.7463 | $3.918 |
| kimi-k2.6 | moonshot | $1.213 | $5.037 |
| kimi-k2.7-code | moonshot | $1.213 | $5.037 |
| kimi-k3 | moonshot | $4.264 | $18.66 |
| kimi-k3.1-pro | moonshot | $2.906 | $13.30 |
| kimi-k3.1-pro-highspeed | moonshot | $5.812 | $30.40 |
| minimax-m2.5 | minimax | $0.3918 | $1.567 |
| minimax-m2.7 | minimax | $0.4478 | $1.71 |
| minimax-m3 | minimax | $0.3918 | $1.567 |
| minimax-m3.1-flash | minimax | $0.1969 | $0.7875 |
| qwen-flash | qwen | $0.03198 | $0.3198 |
| qwen-long | qwen | $0.1066 | $0.4264 |
| qwen-plus | qwen | $0.1706 | $0.4264 |
| qwen-plus-latest | qwen | $0.1706 | $0.4264 |
| qwen3-omni-flash | qwen | $0.3838 | $1.471 |
| qwen3-vl-plus | qwen | $0.2132 | $2.132 |
| qwen3.5-122b-a10b | qwen | $0.1706 | $1.365 |
| qwen3.5-27b | qwen | $0.1279 | $1.023 |
| qwen3.5-35b-a3b | qwen | $0.08529 | $0.6823 |
| qwen3.5-397b-a17b | qwen | $0.2559 | $1.535 |
| qwen3.5-flash | qwen | $0.04264 | $0.3731 |
| qwen3.5-plus | qwen | $0.1706 | $1.023 |
| qwen3.6-27b | qwen | $0.5597 | $3.358 |
| qwen3.6-35b-a3b | qwen | $0.3358 | $2.015 |
| qwen3.6-flash | qwen | $0.2239 | $1.343 |
| qwen3.6-plus | qwen | $0.3731 | $2.239 |
| qwen3.7-flash | qwen | $0.03731 | $0.1493 |
| qwen3.7-max | qwen | $1.279 | $3.838 |
| qwen3.7-plus | qwen | $0.3731 | $1.493 |
| qwen3.8-flash | qwen | $0.1493 | $0.5037 |
| qwen3.8-max | qwen | $2.559 | $7.676 |
| qwen4-max | qwen | $1.766 | $5.30 |

## Pricing rules

- Peak hours: deepseek-v4.1-flash costs 2× the listed rate on weekdays 09:00–12:00 and 14:00–18:00 China time (01:00–04:00 and 06:00–10:00 UTC), excluding China public holidays. The listed rate is the off-peak rate.
- Long inputs (multiplier on the listed rate, by input tokens): qwen3.5-flash 1× to 128K, 4× to 256K, then 6×; qwen3.6-plus 1× to 256K, then 4×; qwen3.7-flash 1× to 32K, 3× to 256K, then 6×; qwen3.5-plus 1× to 128K, 2.5× to 256K, then 5×; qwen3.7-plus 1× to 256K, then 3×; minimax-m3 1× to 512K, then 2×; hy3-preview 1× to 16K, then up to 1.6× input and 2× output.
- The cost of each request, including any peak or long-input rate, is recorded in your usage logs.

## MCP server

Connect any MCP client to https://api.stewerd.com/mcp over Streamable HTTP with your Stewerd key. Tools: `list_models`, `chat`. Calls are billed exactly like the API.

```json
{
  "mcpServers": {
    "stewerd": {
      "type": "http",
      "url": "https://api.stewerd.com/mcp",
      "headers": { "Authorization": "Bearer ql_live_..." }
    }
  }
}
```

## Errors

- 401: Missing or invalid API key. Check the key and the Authorization header.
- 402: Insufficient credit. Stewerd has no free tier: add credit in your dashboard.
- 400: Malformed request, or an unknown model id.
- 429: Rate limit reached for this key (default 120 requests a minute). Back off and retry after the Retry-After header.
- 502: The upstream provider failed. Retry after a short delay.

## Auto routing (stewerd/auto)

Send `"model": "stewerd/auto"` and the gateway picks a model locally (no network call, sub-millisecond). Prompt length, code blocks, reasoning keywords, `tools`, JSON `response_format` and message count determine the tier.

| Tier | Signal | Resolved model |
|---|---|---|
| simple | Short prompt, no code or reasoning | qwen3.5-plus |
| standard | Medium prompt or moderate complexity | qwen3.7-plus |
| complex | Long prompt, code, reasoning, tools, JSON schema | qwen3.8-max |

Resolution order: `@preset/` → `stewerd/auto` → fallback chain. Responses carry `x-stewerd-auto-tier` and `x-stewerd-model`.

## Response caching

Add `x-stewerd-cache: on` to a non-streaming `POST /v1/chat/completions` (temperature 0 or unset). Identical prompts skip the upstream, are billed at $0, and show `x-stewerd-cache: hit`. TTL defaults to 3600 s; override with `x-stewerd-cache-ttl` (60–86 400). Not cached: BYOK targets, file parts, tool-call responses, fallback answers.

## PII redaction

Enable with `x-stewerd-pii: mask` per request, or set `pii_mask = true` on the API key. Emails, phones, Luhn-valid card numbers, IBANs and US SSNs in string message content are replaced with placeholders like `[EMAIL_1]` before the upstream sees them, then restored in the response. Names, addresses and free-text PII are not detected.

## Latency telemetry

- `x-stewerd-overhead-ms`: Time inside the gateway (auth, routing, metering)
- `x-stewerd-ttft-ms`: Time to first token (stream) or first byte
- `Server-Timing`: overhead;dur=N, ttft;dur=N — readable in browser DevTools

## Agent keys

Agent keys start with `ql_agent_`, carry a daily spend cap and an optional model allow-list, and cannot reach BYOK targets. Over-limit requests return `403 agent_daily_limit_reached`. Discovery manifests: `/.well-known/poppy.json` and `/.well-known/agent.json` on the gateway.
