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

# 网关与鉴权

> 了解 TTAPI 的 API 网关地址以及身份认证方式

## 概述

TTAPI 网关是所有接口请求的统一入口，负责请求路由、身份验证、流量控制等核心能力。所有接口调用均需通过网关并完成鉴权，未通过鉴权的请求将直接返回 401 错误。

<Callout type="info" title="核心说明：网关域名规范">
  ### 1. 通用 API 域名

  * **主域**：`https://api.ttapi.io`
    备注：基于 Cloudflare 部署，存在同步超时风险；
  * **加速域**：`https://api.ttapi.org`
    备注：请求耗时较长的接口推荐使用此域名，可降低延迟。

  ### 2. Midjourney 托管 API 专属域名

  * **主域**：`https://hold.ttapi.io`
    备注：基于 Cloudflare 部署，存在同步超时风险；
  * **加速域**：`https://hold.ttapi.org`
    备注：可有效降低访问延迟，提升请求稳定性。

  ### 3. Claude Code 域名

  * **主域**：`https://cc.ttapi.io`
    备注：基于 Cloudflare 部署，存在同步超时风险；
  * **加速域**：`https://cc.ttapi.org`
    备注：可有效降低访问延迟，提升请求稳定性。
</Callout>

## 一、鉴权方式

所有接口均通过请求头携带 `TT-API-KEY` 字段完成鉴权，该字段可在 [开发者控制台](https://dashboard.ttapi.io/) 获取。

#### 鉴权规则

* 字段位置：HTTP Request Header
* 字段名称：`TT-API-KEY`（大小写敏感）

## 二、网关请求规范

| 项    | 要求                           |
| ---- | ---------------------------- |
| 请求协议 | HTTPS（强制，禁止 HTTP）            |
| 请求方法 | 按接口定义使用（POST/GET/PUT/DELETE） |
| 字符编码 | UTF-8                        |
| 内容类型 | JSON（application/json）       |

## 三、鉴权错误码

| 错误码 | 解决方案                                          |
| --- | --------------------------------------------- |
| 401 | 检查请求头是否携带 `TT-API-KEY` 字段以及 `TT-API-KEY` 是否正确 |

#### 错误响应格式

所有鉴权错误均返回统一格式：

```json theme={null}
{
    "status": "FAILED",
    "message": "Wrong TT-API-KEY or email is not activated."
}
```
