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

# 为什么请求返回 401 Unauthorized？

> 401 错误居高不下？分析最常见的 3 种原因并提供对应的快速修复方法。

收到 401 Unauthorized 意味着 Sub2API 网关未能识别你的身份。在排除网络问题后，绝大多数 401 都由下面三种原因导致。按照表格逐项排查，通常可以在几分钟内解决。

## 快速排查表

| 原因             | 常见表现              | 修复方法                                    |
| -------------- | ----------------- | --------------------------------------- |
| Header 格式错误    | 拼错 `Bearer` 或遗漏空格 | 改为 `Authorization: Bearer YOUR_API_KEY` |
| API Key 已删除或失效 | Key 曾在控制台中被手动删除   | 登录控制台重新创建 API Key                       |
| Key 内有多余空格     | 复制时前后带空格或换行       | 对 Key 做 trim 处理后再放入 Header              |

## 正确的 Header 示例

下面是一个格式完全正确的请求 Header：

```http theme={null}
Authorization: Bearer sk-sub2api-xxxxxxxxxxxx
Content-Type: application/json
```

<Warning>
  请特别注意以下几点：
</Warning>

* `Bearer` 首字母大写，后面紧跟一个空格
* API Key 前后不要有空格、换行或引号
* Header 名称必须是 `Authorization`，不要写成 `Auth`、`Api-Key` 等其他形式

## 常见错误写法

<CodeGroup>
  ```http 缺少 Bearer theme={null}
  Authorization: sk-sub2api-xxxxxxxxxxxx
  ```

  ```http 拼写错误 theme={null}
  Authorization: Bearer sk-sub2api-xxxxxxxxxxxx
  ```

  ```http Key 带引号 theme={null}
  Authorization: Bearer "sk-sub2api-xxxxxxxxxxxx"
  ```
</CodeGroup>

## 如果以上都确认无误仍然 401

1. 检查 API Key 是否仍在控制台中有效列表里（可能已被你或团队成员误删）
2. 确认发送请求的环境与创建 Key 时的账户一致
3. 检查是否有代理或中间件篡改了 Header

如需更完整的诊断流程和高级排查步骤，请参阅 [401 完整排错指南](/troubleshooting/401)。
