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

# 身份验证

> 使用控制台中的工作区 API 密钥对 Fetch Hive API 请求进行身份验证

# 身份验证

使用工作区 API 密钥对公开的 Fetch Hive API 请求进行身份验证。

## 身份验证请求头

在每个请求的 `Authorization` 请求头中发送你的 API 密钥：

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

Fetch Hive 对公开的 invoke 接口和公开的资源接口使用相同的 bearer 请求头。

## 如何创建 API 密钥？ <a href="#create-api-key" id="create-api-key" />

打开 **Settings**，然后点击 **API Keys**。

如果你的工作区还没有默认密钥，点击 **Create Default Key**。

如果你想为特定服务或环境创建另一个密钥，点击 **Add API Key**。

选择你想使用的环境：

* **Production**
* **Staging**
* **Development**

当 Fetch Hive 显示 **Your New API Key** 时复制完整密钥。在对话框关闭后，Fetch Hive 通常只显示密钥前缀。

{/* Add screenshot: Your New API Key dialog with one-time full key reveal */}

## 示例请求

```bash theme={null}
curl 'https://api.fetchhive.com/v1/prompt/invoke' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  --data-raw '{
    "deployment": "YOUR_DEPLOYMENT_NAME",
    "variant": "YOUR_VARIANT_NAME",
    "inputs": {
      "text": "Fetch Hive helps teams ship AI products faster."
    },
    "streaming": true
  }' \
  --compressed
```

## 身份验证失败时会发生什么？

如果 API 密钥缺失、无效或已被吊销，Fetch Hive 会返回错误响应。

```json theme={null}
{
  "error": "Invalid access."
}
```

有关常见状态码和错误结构，请参阅[错误和速率限制](./errors-and-rate-limits)。有关控制台中的 API 密钥管理，请参阅 [API keys](../workspace/api-keys)。
