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

# 環境變量

> 通過環境變量進行配置。

## 變量

| 變量 | 是否必需 | 默認值 | 使用方 | 說明 |
| - | - | - | - | - |
| `THEO_API_KEY` | ✅ | — | CLI、SDK、MCP | 你的 `theo_sk_...` API 密鑰 |
| `THEO_BASE_URL` | — | `https://www.hitheo.ai` | CLI、SDK、MCP | 覆蓋 API 基礎 URL |
| `THEO_ALLOW_JS_CONFIG` | — | 未設置 | MCP | 設為 `1` 時，允許 MCP 服務器加載 `theo.config.js` / `theo.config.ts`，而不是 `theo.config.json`。出於[安全](/mcp/security#the-json-only-config-sandbox)考慮，默認關閉——JS/TS 配置會執行來自工作目錄的任意代碼。 |

<Warning>
  `THEO_BASE_URL` 默認使用規範的 `www` 主機名。若將其指向 `https://hitheo.ai`（不帶 `www`），根域名會以 307 重定向到 `www`，而部分 HTTP 客戶端在處理重定向時會剝離 `Authorization` 請求頭——導致首次請求出現 401。參見[401 故障排查](/troubleshooting/401-errors)。
</Warning>

## 使用場景

* **CLI** — `theo complete`、`theo status`、`theo verify`、`theo skill publish` 都會讀取 `THEO_API_KEY`。`theo status` 還會同時探測根域名和 `www`，無論 `THEO_BASE_URL` 指向哪一個，因此配置錯誤的環境變量會以警告形式呈現出來。
* **MCP 服務器** — `@hitheo/mcp` 服務器在啓動時讀取 `THEO_API_KEY`，並將其注入到每一次工具調用中。自 `@hitheo/mcp@0.2.0` 起，`THEO_BASE_URL` 默認值為 `https://www.hitheo.ai`。
* **SDK** — 如需以編程方式使用，直接傳入密鑰：

```typescript theme={null}
const theo = new Theo({ apiKey: process.env.THEO_API_KEY! });
```

## 設置變量

<CodeGroup>
  ```bash Shell theme={null}
  export THEO_API_KEY=theo_sk_live_a1b2c3d4e5f6...
  ```

  ```bash .env file theme={null}
  THEO_API_KEY=theo_sk_live_a1b2c3d4e5f6...
  THEO_BASE_URL=https://www.hitheo.ai
  ```
</CodeGroup>

## 優先級

1. 顯式的構造函數參數（SDK）或 CLI 標誌
2. 環境變量
3. 當前目錄下的 `.env` 文件
   顯式指定的值始終會覆蓋環境變量。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.