# 自动选模型 (/zh-CN/docs/auto-router)

把 `model` 写成 `auto`，OhMyGPT 会按最新一条用户消息要做的事为每个请求挑模型：简短的一问一答用快而便宜的模型，日常工作用能力全面的模型，要证明、算法、架构设计或排错时用最强的一档。写 `ohmygpt/auto` 或 OpenRouter 的 `openrouter/auto` 效果相同。

```bash
curl https://api.ohmygpt.com/v1/chat/completions \
  -H "Authorization: Bearer $OHMYGPT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "auto",
    "messages": [{"role": "user", "content": "hi"}]
  }'
```

响应里的 `model` 是实际回答的模型：

```json
{
  "model": "deepseek/deepseek-v4.1-flash-1017",
  "choices": [{"message": {"role": "assistant", "content": "Hi! How can I help you today?"}}]
}
```

按这个模型的标准价格计费，选模型本身不另收费。Chat Completions、Responses 和 Messages 都能用，流式与非流式都支持；Embeddings 这类不生成对话回复的接口不支持，会返回 `400 unsupported_endpoint`。

## 多轮对话 [#多轮对话]

带上 `prompt_cache_key`，同一段对话会留在同一个模型上，提示缓存继续生效。对话中后面的问题更难时会换到更强的模型，但不会再换回较弱的：

| 这一轮 | 模型 |
|---|---|
| `hi` | `deepseek/deepseek-v4.1-flash-1017` |
| `Prove that there are infinitely many primes, briefly.` | `openai/gpt-6.1-sol` |
| `thanks` | `openai/gpt-6.1-sol` |

不带 `prompt_cache_key` 时，每个请求各自挑模型。

## 选项 [#选项]

和 OpenRouter 一样，在 `plugins` 里加一项 `auto-router`：

```json
{
  "model": "auto",
  "plugins": [{
    "id": "auto-router",
    "allowed_models": ["openai/*", "google/*"],
    "excluded_models": ["openai/gpt-5.4-nano"],
    "cost_tier": "low"
  }],
  "messages": [{"role": "user", "content": "explain why the sky is blue"}]
}
```

| 字段 | 作用 |
|---|---|
| `allowed_models` | 只在这些模型里挑。`*` 匹配 ID 的任意部分，例如 `openai/*`。 |
| `excluded_models` | 不挑这些模型，即使 `allowed_models` 匹配到也不挑。 |
| `cost_tier` | `low` 比默认便宜一档，`high` 比默认强一档；不写时是 `medium`。 |

`cost_tier` 写了别的值，或两个列表筛完一个模型都不剩，会返回 `400 invalid_parameter` 并指出是哪个字段。`auto-router` 这一项不会转给模型。
