---
title: Magpie | RunAPI
description: 将 RunAPI 添加到 Magpie，并为 Claude Code 或 Codex 选择模型。
url: https://runapi.ai/zh-CN/docs/resources/tool-integrations/magpie.md
canonical: https://runapi.ai/zh-CN/docs/resources/tool-integrations/magpie
locale: zh-CN
---

> HTML 版本: https://runapi.ai/zh-CN/docs/resources/tool-integrations/magpie
> 智能体网站索引: https://runapi.ai/llms.txt

# Magpie

## 安装与准备

安装 [Magpie][1] 的最新稳定版。各平台的安装方法请参阅[官方参考文档][2]。另行安装 Claude Code 或 Codex。



[1]: https://usemagpie.ai
[2]: https://github.com/yetone/magpie/blob/main/docs/reference.md

按照[身份验证指南](https://runapi.ai/zh-CN/docs/guides/authentication.md)创建专用的标准 API
密钥。从[模型目录](https://runapi.ai/zh-CN/models)复制模型 ID 及其支持的协议。更换提供商前，备份代理配置。

## 添加兼容 OpenAI 的提供商

支持 Chat Completions 的模型使用此分支。运行命令前替换两个占位符。`url=` 基础地址以 `/v1` 结尾；Magpie
会追加 `/chat/completions`。

```shell
magpie provider add runapi-chat url=https://runapi.ai/v1 key=YOUR_RUNAPI_API_KEY models=YOUR_RUNAPI_MODEL_ID
```

## 添加兼容 Anthropic 的提供商

支持 Anthropic Messages 的模型使用此分支。`anthropic=` 基础地址不含 `/v1`；Magpie 会追加
`/v1/messages`。

```shell
magpie provider add runapi-anthropic anthropic=https://runapi.ai key=YOUR_RUNAPI_API_KEY models=YOUR_RUNAPI_MODEL_ID
```

先选择一个分支。Magpie 会拒绝使用相同密钥添加第二个提供商。如需保留两个提供商，请分别创建不同的 RunAPI 专用密钥。将 RunAPI
密钥保存在 Magpie 中，不要存入代码仓库。

## 为代理分配模型

启动 Magpie 并保持网关运行。在 Agents 界面选择 Claude Code 或 Codex，再选择 RunAPI
提供商下的模型。CLI 也提供相同的选择功能。使用所选提供商和模型 ID 运行一条命令。

```shell
magpie serve
```

在另一个终端中选择模型。

```shell
magpie models
magpie claude runapi-chat/YOUR_RUNAPI_MODEL_ID
magpie codex runapi-chat/YOUR_RUNAPI_MODEL_ID
```

对于 Anthropic 分支，将 `runapi-chat` 替换为 `runapi-anthropic`。Magpie 在本地使用
`provider/model`，并将原始模型 ID 转发给 RunAPI。代理通过 `127.0.0.1:3425` 连接 Magpie，无需
RunAPI 密钥。Codex 使用本地 Responses 接口，这并不意味着 RunAPI 收到的是 Responses
请求。这两个提供商分支在 RunAPI 端分别选择 Chat Completions 或 Messages。

## 验证配置

使用以下命令检查提供商和所选模型，然后启动新的代理会话并发送简短提示词。

```shell
magpie version
magpie providers
magpie claude
magpie codex
```

在 RunAPI 用量记录中确认预期的模型和请求。仅凭代理成功响应，无法确定实际处理请求的提供商。Magpie 的 Test
models、Detect APIs 和提供商测试可能发送推理请求。

已在 Linux 上使用 Magpie 0.1.1307 和 Claude Code 2.1.295
检查配置及本地路由。两个提供商分支均返回了固定的本地 fixture 响应。本指南未测试真实 RunAPI 推理或 Codex
推理。用于代理任务前，请检查所选模型的协议和工具支持。

## 故障排查

如果 Magpie 提示该密钥已添加提供商，请复用该提供商，或为第二个分支使用不同的专用密钥。此错误已在本地复现。

在本地 fixture 测试中，停止配置的服务器后，复现了 `no model list` 和 `connection
refused`。请检查地址和服务器可用性，再通过 `models=` 指定准确的模型 ID。代理使用本地网关期间，请保持 Magpie 运行。

Claude Code 对 fixture ID 报告了 `unrecognized_model`，但仍返回了 fixture
响应。如果出现此警告，请检查原始模型 ID 和 Claude Code 的模型配置。fixture 未验证上下文限制、工具调用或模型质量。

## 恢复原有配置

移除提供商前，先恢复代理配置。以下命令将各代理恢复到之前的配置。

```shell
magpie claude default
magpie codex default
magpie provider rm runapi-chat
magpie provider rm runapi-anthropic
```

仅移除自己添加的提供商。不再需要专用 RunAPI 密钥时，请撤销这些密钥。如果还手动更改了其他配置，请恢复备份。

## 后续步骤

参阅 [LLM API 快速入门](https://runapi.ai/zh-CN/docs/guides/llm-api/quickstart.md)，了解 RunAPI
公开协议示例，并在[模型目录](https://runapi.ai/zh-CN/models)查看支持的模型。Magpie 官方参考文档还列出了 Grok Build 集成；本指南未测试
Grok Build。

---

## RunAPI 的更多内容

- [首页](https://runapi.ai/zh-CN/.md)
- [模型目录](https://runapi.ai/zh-CN/models.md)
- [定价](https://runapi.ai/zh-CN/pricing.md)
- [提供方](https://runapi.ai/zh-CN/models)
- [文档](https://runapi.ai/zh-CN/docs/guides)
- [SDK](https://runapi.ai/zh-CN/sdk.md)
- [CLI](https://runapi.ai/zh-CN/cli.md)
- [MCP Server](https://runapi.ai/zh-CN/mcp.md)
- [x402](https://runapi.ai/zh-CN/x402.md)
- [Claude Code 与 Cursor](https://runapi.ai/zh-CN/claude-code-vs-cursor.md)
- [Cursor API 设置](https://runapi.ai/zh-CN/cursor-api-setup.md)
- [RunAPI 与 OpenRouter](https://runapi.ai/zh-CN/openrouter-alternative.md)
- [企业版](https://runapi.ai/zh-CN/contact.md)
- [联系](https://runapi.ai/zh-CN/contact.md)
- [服务条款](https://runapi.ai/zh-CN/terms.md)
- [隐私政策](https://runapi.ai/zh-CN/privacy.md)
- [智能体网站索引](https://runapi.ai/llms.txt)

联系我们: contact@runapi.ai

## 结构化数据

```json
[
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-CN",
    "@type": "WebSite",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-CN",
    "potentialAction": {
      "@type": "SearchAction",
      "target": {
        "@type": "EntryPoint",
        "urlTemplate": "https://runapi.ai/zh-CN/models?q={search_term_string}"
      },
      "query-input": "required name=search_term_string"
    }
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-CN",
    "@type": "Organization",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-CN",
    "logo": {
      "@type": "ImageObject",
      "url": "https://runapi.ai/zh-CNicon.svg"
    },
    "sameAs": [
      "https://github.com/runapi-ai"
    ]
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-CN",
    "@type": "TechArticle",
    "headline": "Magpie",
    "description": "将 RunAPI 添加到 Magpie，并为 Claude Code 或 Codex 选择模型。",
    "url": "https://runapi.ai/zh-CN/docs/resources/tool-integrations/magpie",
    "mainEntityOfPage": "https://runapi.ai/zh-CN/docs/resources/tool-integrations/magpie"
  }
]
```
