# Claude Code 與 Codex 設定

設定 Claude Code 和 Codex，讓模型呼叫透過 Felo API Platform 路由。

本指南說明如何讓 Agent 使用者端使用 Felo API Platform LLM API。當你希望 Claude Code 或 Codex 透過 Felo API Platform 路由模型呼叫，而不是直接呼叫模型廠商時，請使用本頁。

::: warning 需要 Felo API 充值額度
Felo 模型呼叫從 **Felo API Platform 的預付服務額度**扣費。**Felo Pro 訂閱不包含 API/模型呼叫額度**，不能用於支付這些呼叫。首次請求前請到 [Console Billing](https://openapi.felo.ai/console/billing) 充值。
:::

使用任一使用者端前，先設定 `FELO_API_KEY`。

```bash
export FELO_API_KEY="YOUR_API_KEY"
```

## 支援的使用者端路徑

| 使用者端或 API 型別 | 推薦 Felo endpoint | 模型範例 | 說明 |
|-----------------------|-------------------|---------------|-------|
| Claude Code | `POST /api/v1/messages` | `claude-sonnet-5` | Claude Code 使用 Anthropic Messages wire 格式。 |
| Codex | `POST /api/v1/responses` | `gpt-5.6-sol` | Codex 自訂 providers 推薦使用 Responses API。 |
| Chat Completions | `POST /api/v1/chat/completions` | `gpt-5.6-sol` | 適合 SDKs 或 伺服器端整合。 |

## Claude Code

Claude Code 應使用 Anthropic-compatible Messages endpoint。

```bash
export ANTHROPIC_API_KEY="$FELO_API_KEY"
export ANTHROPIC_BASE_URL="https://openapi.felo.ai/api"
export ANTHROPIC_MODEL="claude-sonnet-5"

claude
```

Anthropic base URL 有意省略 `/v1`，因為 Claude Code 和 Anthropic SDK 會在 configured API host 後追加 `/v1/messages`。

## Codex

Codex 應使用 OpenAI-compatible Responses endpoint。在 `~/.codex/config.toml` 中加入 Felo provider。

```toml
model_provider = "felo"
model = "gpt-5.6-sol"

[model_providers.felo]
name = "Felo API Platform LLM API"
base_url = "https://openapi.felo.ai/api/v1"
env_key = "FELO_API_KEY"
wire_api = "responses"
```

Codex endpoint authentication 和 endpoint selection 應放在 user-level Codex config 中。不要把 API key 寫入專案檔案。

## 計費與額度

模型呼叫與 Felo Pro 分開計費：

- 每次 Felo 模型請求都會從 Felo API Platform 的服務額度餘額扣費。
- Felo Pro 訂閱不贈送 API 額度，也不會讓模型呼叫免費。
- 在 [Console Billing](https://openapi.felo.ai/console/billing) 充值和查看用量。
- 餘額不足時，API 回傳 `402 INSUFFICIENT_CREDITS`。

完整規則見 [Billing and Credits](https://openapi.felo.ai/zh-TW/docs/faq/billing-and-credits.md)。

## 官方文件

- [Claude Code environment variables](https://code.claude.com/docs/en/env-vars)
- [Claude Code model configuration](https://code.claude.com/docs/en/model-config)
- [Codex advanced configuration](https://developers.openai.com/codex/config-advanced#custom-model-providers)
