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

# 认证方式

> 说明 Bearer Token、原生兼容认证头、登录态和 OAuth 浏览器流程。

# 认证方式

Geeknow API 支持 API Key 认证、原生兼容认证头和浏览器登录态三种访问方式。调用前先确认目标接口使用公开 API 鉴权还是浏览器登录态。

## Bearer Token

用于大多数公开 API 接口，包括：

* `/v1/*`
* `/v1beta/*`
* `/mj/*`
* `/kling/v1/*`
* `/dashboard/billing/*`

请求头：

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

## Claude 原生兼容头

用于 `POST /v1/messages` 等 Claude 原生格式页面：

```http theme={null}
x-api-key: YOUR_API_KEY
anthropic-version: 2023-06-01
```

## Gemini 原生兼容头

用于 `GET /v1beta/models` 与 `POST /v1beta/models/{model}:{action}`：

```http theme={null}
x-goog-api-key: YOUR_API_KEY
```

也兼容 `?key=YOUR_API_KEY` 的查询参数风格。

## 用户登录态

用于 `/api/user/*`、后台管理和部分前端仪表盘接口。典型特征：

* 需要先在浏览器中完成登录，并在请求中携带有效登录态。
* 失败时很多接口仍返回 HTTP `200`，但 `success` 为 `false`。

## OAuth 浏览器流

### 1. 生成 `state`

```http theme={null}
GET /api/oauth/state
```

成功响应：

```json theme={null}
{
  "success": true,
  "message": "",
  "data": "a1b2c3d4e5f6"
}
```

### 2. 跳转到标准 OAuth 提供商

```http theme={null}
GET /api/oauth/{provider}
```

这个接口用于 OAuth 浏览器回调。完成 `state` 校验和用户授权后，会绑定或创建账户并建立登录态。

常见 `provider` 由实际启用的 OAuth 配置决定，例如：

* `github`
* `discord`
* `oidc`
* `linuxdo`

## 认证失败时的常见返回

### 公开 API 接口

```json theme={null}
{
  "error": {
    "message": "Invalid API key provided",
    "type": "invalid_request_error",
    "param": "",
    "code": "invalid_api_key"
  }
}
```

### `/api/*` 路由

```json theme={null}
{
  "success": false,
  "message": "无效的令牌"
}
```

## 相关页面

* [账户余额与用量](./billing)
* [文本接口概览](../texts/overview)
