---
title: AI Gateway 运作方式与端点
description: 一把 API 密钥、一个网址，就能使用 Claude、GPT、Gemini 和你自己的模型。Gateway 会挑选模型，在送出前先把每个请求的费用预留在你的额度里，并记录每一个请求。
url: https://agentlab.cresclab.com/docs/zh-cn/gateway
language: zh-Hans
updated: 2026-11-04
---

# AI Gateway 运作方式与端点

一把 API 密钥、一个网址，就能使用 Claude、GPT、Gemini 和你自己的模型。Gateway 会挑选模型，在送出前先把每个请求的费用预留在你的额度里，并记录每一个请求。

想先了解 AI Gateway 是什么、和 API proxy 差在哪、怎么挑，看 [AI Gateway 介绍](https://agentlab.cresclab.com/zh-cn/gateway)。这份文档讲怎么接上与怎么运作。

## Gateway 做什么

你的工具改用 Gateway API 密钥调用 `https://api.agentlab.cresclab.com`，不再直接调用模型供应商。每个请求，Gateway 会：

1. **检查密钥** 密钥属于你的工作区，可以把花费归属到部门。
2. **挑选模型** 指定了模型就照指定的用；`auto` 会依任务难度挑一个。
3. **预留费用** 送出前，先把这个请求最多可能花的费用预留在你的额度里。放不下的请求会被拒绝，不收任何费用。
4. **记录下来** 记录密钥、模型、token、费用和耗时，不记录提示词和回复的内容。

Gateway 支持三种协定，现有的用户端只要改 base URL 就能接上：

| 端点                        | 协定                     | 谁在用                                      |
| --------------------------- | ------------------------ | ------------------------------------------- |
| `POST /v1/messages`         | Anthropic Messages       | Claude Code、Anthropic SDK                  |
| `POST /v1/responses`        | OpenAI Responses         | Codex、OpenAI SDK（`responses`）            |
| `POST /v1/chat/completions` | OpenAI Chat Completions  | Cursor、OpenAI SDK、大多数框架、直接送 HTTP |
| `GET /v1/models`            | OpenAI 或 Anthropic 清单 | 所有用户端：列出 `auto` 和允许使用的模型    |

## 从这里开始

- [快速入门](https://agentlab.cresclab.com/docs/zh-cn/gateway/quickstart.md): 几个可以直接复制的步骤，接上 Claude Code、Codex、Cursor、OpenAI SDK、Anthropic SDK 或 curl。
- [API 密钥](https://agentlab.cresclab.com/docs/zh-cn/gateway/keys.md): 创建密钥、归属到部门、设置限制、轮替和撤销。
- [自动选择模型](https://agentlab.cresclab.com/docs/zh-cn/gateway/auto.md): `auto` 怎么挑模型，以及回复怎么告诉你是哪个模型回答的。
- [额度与预算](https://agentlab.cresclab.com/docs/zh-cn/gateway/limits.md): 每月预算、部门上限、速率上限，以及三种 429。
- [用量与导出](https://agentlab.cresclab.com/docs/zh-cn/gateway/usage.md): 用量页、终端用户归属和每月 CSV 导出。
- [错误代码](https://agentlab.cresclab.com/docs/zh-cn/gateway/errors.md): 每个错误代码的状态码、能不能重试、怎么修。

## 参考数据

- [API 参考](https://agentlab.cresclab.com/docs/zh-cn/gateway/api.md)：端点、标头和 OpenAPI 文档。
- [数据处理](https://agentlab.cresclab.com/docs/zh-cn/gateway/data.md)：请求的哪些数据会保存、哪些不会。
- [自行架设](https://agentlab.cresclab.com/docs/zh-cn/gateway/self-hosting.md)：在你自己的网络里运行 Gateway。
