---
title: Magpie | RunAPI
description: 將 RunAPI 添加到 Magpie，併為 Claude Code 或 Codex 選擇模型。
url: https://runapi.ai/zh-HK/docs/resources/tool-integrations/magpie.md
canonical: https://runapi.ai/zh-HK/docs/resources/tool-integrations/magpie
locale: zh-HK
---

> HTML 版本: https://runapi.ai/zh-HK/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-HK/docs/guides/authentication.md)創建專用的標準 API
密鑰。從[模型目錄](https://runapi.ai/zh-HK/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-HK/docs/guides/llm-api/quickstart.md)，瞭解 RunAPI
公開協議示例，並在[模型目錄](https://runapi.ai/zh-HK/models)查看支持的模型。Magpie 官方參考文檔還列出了 Grok Build 集成；本指南未測試
Grok Build。

---

## RunAPI 的更多內容

- [首頁](https://runapi.ai/zh-HK/.md)
- [模型目錄](https://runapi.ai/zh-HK/models.md)
- [收費](https://runapi.ai/zh-HK/pricing.md)
- [服務商](https://runapi.ai/zh-HK/models)
- [文件](https://runapi.ai/zh-HK/docs/guides)
- [SDK](https://runapi.ai/zh-HK/sdk.md)
- [CLI](https://runapi.ai/zh-HK/cli.md)
- [MCP Server](https://runapi.ai/zh-HK/mcp.md)
- [x402](https://runapi.ai/zh-HK/x402.md)
- [Claude Code 與 Cursor](https://runapi.ai/zh-HK/claude-code-vs-cursor.md)
- [Cursor API 設定](https://runapi.ai/zh-HK/cursor-api-setup.md)
- [RunAPI 與 OpenRouter](https://runapi.ai/zh-HK/openrouter-alternative.md)
- [企業版](https://runapi.ai/zh-HK/contact.md)
- [聯絡](https://runapi.ai/zh-HK/contact.md)
- [條款](https://runapi.ai/zh-HK/terms.md)
- [私隱](https://runapi.ai/zh-HK/privacy.md)
- [智能代理網站索引](https://runapi.ai/llms.txt)

聯絡我們: contact@runapi.ai

## 結構化資料

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