> ## 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.