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

# 认证

> 了解如何使用 API Key 进行身份验证，所有 API 请求都需要在请求头中包含有效的 API Key。

## API Key 认证

### 请求头格式

所有 API 请求都需要包含以下请求头：

```
ailabapi-api-key: YOUR_API_KEY
```

### 示例

```bash theme={null}
curl -X POST "https://api.aihairstyle.cn/api/portrait/effects/hairstyle-editor-pro" \
  -H "ailabapi-api-key: YOUR_API_KEY" \
  -F "image=@/path/to/your/image.jpg"
```

## 获取 API Key

要获取 API Key，请按照以下步骤操作：

1. **注册账号**：访问 [AI发型设计 开发者中心](https://www.aihairstyle.cn/developer-platform)
2. **登录平台**：注册/登录账号
3. **创建应用**：在开发者平台创建新应用
4. **获取 API Key**：复制生成的 API Key

<Warning>
  API密钥是访问API的凭证，请妥善保管，不要泄露给他人。
</Warning>

## 安全建议

* **保护 API Key**：不要将 API Key 硬编码在客户端代码中
* **环境变量**：将 API Key 存储在环境变量中
* **定期轮换**：定期更换 API Key 以提高安全性
* **访问控制**：限制 API Key 的访问权限

## 错误处理

如果 API Key 无效或缺失，API 将返回以下错误：

```json theme={null}
{
  "error_code": 401,
  "error_msg": "Unauthorized",
  "error_detail": {
    "status_code": 401,
    "code": "UNAUTHORIZED",
    "code_message": "Invalid API key in request",
    "message": "Invalid API key in request"
  }
}
```
