> ## Documentation Index
> Fetch the complete documentation index at: https://docs2.openclaw.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Max API 代理

**claude-max-api-proxy** 是一個社群 npm 套件（不是 OpenClaw 外掛），可將 Claude Max/Pro 訂閱公開為 OpenAI 相容的 API 端點，因此你可以將任何 OpenAI 相容工具指向你的訂閱，而不是 Anthropic API 金鑰。

<Warning>
  僅提供技術相容性，並非官方核准的路徑。Anthropic 過去曾封鎖 Claude Code 以外的部分訂閱用法；在依賴此方式前，請先確認 Anthropic 目前的計費規則。

  Anthropic 的 Claude Code 文件將 `claude -p` 描述為 Agent SDK／程式化使用。截至 Anthropic 2026 年 6 月 15 日的支援更新，Claude Agent SDK、`claude -p` 與第三方應用程式使用量都會計入已登入訂閱的使用限制（先前公告的獨立 Agent SDK 點數方案已暫停）。請參閱 Anthropic 的 [Agent SDK 方案文章](https://support.claude.com/en/articles/15036540-use-the-claude-agent-sdk-with-your-claude-plan)、[Pro/Max](https://support.claude.com/en/articles/11145838-use-claude-code-with-your-pro-or-max-plan) 與 [Team/Enterprise](https://support.claude.com/en/articles/11845131-use-claude-code-with-your-team-or-enterprise-plan) 方案文章，以及 [Anthropic provider](/zh-TW/providers/anthropic)，了解 OpenClaw 自身的 Claude 命令列介面計費說明。
</Warning>

## 為什麼使用此方式

| 方式               | 成本路徑                              | 最適合               |
| ---------------- | --------------------------------- | ----------------- |
| Anthropic API 金鑰 | 透過 Claude Console 依 token 付費      | 生產應用程式、共用自動化、大量使用 |
| Claude 訂閱代理      | Claude Code / `claude -p` 方案與點數規則 | 使用相容工具的個人實驗       |

此代理可讓 Claude Max 或 Pro 訂閱搭配 OpenAI 相容工具使用。這不是無限制的固定費率路徑，它會繼承 Claude Code 的使用限制。對於生產使用，API 金鑰仍是更清楚的計費路徑。

## 運作方式

```text theme={"theme":{"light":"min-light","dark":"min-dark"}}
Your App -> claude-max-api-proxy -> Claude Code CLI / claude -p -> Anthropic
     (OpenAI format)                (converts format)              (uses your login)
```

代理會針對每個請求將 Claude Code 命令列介面作為子程序啟動，將 OpenAI 格式的聊天請求轉換為命令列介面提示，並以 OpenAI 格式串流（或傳回）回應。

## 開始使用

<Steps>
  <Step title="安裝代理">
    需要 Node.js 20+ 與已驗證的 Claude Code 命令列介面。

    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    npm install -g claude-max-api-proxy

    # Verify Claude CLI is authenticated
    claude --version
    claude auth login   # if not already authenticated
    ```
  </Step>

  <Step title="啟動伺服器">
    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    claude-max-api
    # Server runs at http://localhost:3456
    ```
  </Step>

  <Step title="測試代理">
    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    curl http://localhost:3456/health
    curl http://localhost:3456/v1/models

    curl http://localhost:3456/v1/chat/completions \
      -H "Content-Type: application/json" \
      -d '{
        "model": "claude-opus-4",
        "messages": [{"role": "user", "content": "Hello!"}]
      }'
    ```
  </Step>

  <Step title="設定 OpenClaw">
    將 OpenClaw 指向此代理，作為自訂 OpenAI 相容端點：

    ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
    {
      env: {
        OPENAI_API_KEY: "not-needed",
        OPENAI_BASE_URL: "http://localhost:3456/v1",
      },
      agents: {
        defaults: {
          model: { primary: "openai/claude-opus-4" },
        },
      },
    }
    ```
  </Step>
</Steps>

<Note>
  以下模型 ID 是代理自身的目錄，不是 OpenClaw 的 Anthropic 模型參照。每個 ID 都會對應到 Claude Code 命令列介面模型別名（`opus`、`sonnet`、`haiku`），因此只要 Anthropic 在命令列介面中更新該別名，底層模型就會改變。依賴特定對應前，請先查看代理目前的 README。
</Note>

| 模型 ID             | 命令列介面別名  | 目前對應            |
| ----------------- | -------- | --------------- |
| `claude-opus-4`   | `opus`   | Claude Opus 4.5 |
| `claude-sonnet-4` | `sonnet` | Claude Sonnet 4 |
| `claude-haiku-4`  | `haiku`  | Claude Haiku 4  |

## 進階設定

<AccordionGroup>
  <Accordion title="代理風格 OpenAI 相容說明">
    這會使用 OpenClaw 的通用自訂 `/v1` OpenAI 相容路由，與任何其他自架 OpenAI 相容後端的路徑相同：

    * 不會套用僅限原生 OpenAI 的請求塑形。
    * `/fast` 與 `service_tier` 僅適用於直接傳送至 `api.anthropic.com` 的流量；代理路由會保留 `service_tier` 不變（請參閱 [Anthropic provider 快速模式](/zh-TW/providers/anthropic#advanced-configuration)）。
    * 沒有 Responses `store`、提示快取提示，或 OpenAI 推理相容酬載塑形。
    * OpenClaw 的 OpenAI/Codex 歸因標頭（`originator`、`version`、`User-Agent`）只會在原生 `api.openai.com` OAuth 流量中傳送，不會在像此代理這樣的自訂 `OPENAI_BASE_URL` 目標上傳送。
  </Accordion>

  <Accordion title="在 macOS 使用 LaunchAgent 自動啟動">
    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    cat > ~/Library/LaunchAgents/com.claude-max-api.plist << 'EOF'
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>com.claude-max-api</string>
      <key>RunAtLoad</key>
      <true/>
      <key>KeepAlive</key>
      <true/>
      <key>ProgramArguments</key>
      <array>
        <string>/usr/local/bin/node</string>
        <string>/usr/local/lib/node_modules/claude-max-api-proxy/dist/server/standalone.js</string>
      </array>
      <key>EnvironmentVariables</key>
      <dict>
        <key>PATH</key>
        <string>/usr/local/bin:/opt/homebrew/bin:~/.local/bin:/usr/bin:/bin</string>
      </dict>
    </dict>
    </plist>
    EOF

    launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.claude-max-api.plist
    ```
  </Accordion>
</AccordionGroup>

## 注意事項

* 繼承 Claude Code 的 `claude -p` 計費、使用點數與速率限制行為。
* 僅繫結至 `127.0.0.1`；除了命令列介面自身對 Anthropic 的呼叫外，不會將資料傳送到任何第三方伺服器。
* 支援串流回應。
* 啟動時不會檢查驗證失敗，只有在聊天請求實際執行後才會浮現；如果命令列介面尚未驗證，預期第一個請求會失敗，而不是伺服器拒絕啟動。

<Note>
  如需透過 Claude 命令列介面或 API 金鑰進行原生 Anthropic 整合，請參閱 [Anthropic provider](/zh-TW/providers/anthropic)。如需 OpenAI/Codex 訂閱，請參閱 [OpenAI provider](/zh-TW/providers/openai)。
</Note>

## 相關

<CardGroup cols={2}>
  <Card title="Anthropic provider" href="/zh-TW/providers/anthropic" icon="bolt">
    透過 Claude 命令列介面或 API 金鑰進行的原生 OpenClaw 整合。
  </Card>

  <Card title="OpenAI provider" href="/zh-TW/providers/openai" icon="robot">
    適用於 OpenAI/Codex 訂閱。
  </Card>

  <Card title="模型選擇" href="/zh-TW/concepts/model-providers" icon="layers">
    所有供應商、模型參照與容錯移轉行為概覽。
  </Card>

  <Card title="設定" href="/zh-TW/gateway/configuration" icon="gear">
    完整設定參考。
  </Card>
</CardGroup>
