Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Docker

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Check out repository
uses: actions/checkout@v6

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}

- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request' && github.ref_name == github.event.repository.default_branch
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' && github.ref_name == github.event.repository.default_branch }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
57 changes: 35 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ If the configured Claude account is temporarily cooled down after upstream rate
Copy `config.example.yaml` to `config.yaml` and edit as needed:

```yaml
host: "" # bind address, empty = 127.0.0.1
host: "" # bind address, empty = 127.0.0.1
port: 8317

auth-dir: "~/.auth2api" # where OAuth tokens are stored
auth-dir: "~/.auth2api" # where OAuth tokens are stored

api-keys:
- "your-api-key-here" # clients use this to authenticate
- "your-api-key-here" # clients use this to authenticate

body-limit: "200mb" # maximum JSON request body size, useful for large-context usage
body-limit: "200mb" # maximum JSON request body size, useful for large-context usage

cloaking:
mode: "auto" # auto | always | never
mode: "auto" # auto | always | never
strict-mode: false
sensitive-words: []
cache-user-id: false

debug: "off" # off | errors | verbose
debug: "off" # off | errors | verbose
```

Timeouts can also be configured if you run long Claude Code tasks:
Expand All @@ -103,6 +103,7 @@ By default, streaming upstream requests are allowed to run for 10 minutes before
The default request body limit is `200mb`, which is more suitable for large Claude Code contexts than the previous fixed `20mb`.

`debug` now supports three levels:

- `off`: no extra logs
- `errors`: log upstream/network failures and upstream error bodies
- `verbose`: include `errors` logs plus per-request method, path, status, and duration
Expand All @@ -124,12 +125,12 @@ curl http://127.0.0.1:8317/v1/chat/completions \

### Available models

| Model ID | Description |
|----------|-------------|
| `claude-opus-4-6` | Claude Opus 4.6 |
| `claude-sonnet-4-6` | Claude Sonnet 4.6 |
| `claude-haiku-4-5-20251001` | Claude Haiku 4.5 |
| `claude-haiku-4-5` | Alias for Claude Haiku 4.5 |
| Model ID | Description |
| --------------------------- | -------------------------- |
| `claude-opus-4-6` | Claude Opus 4.6 |
| `claude-sonnet-4-6` | Claude Sonnet 4.6 |
| `claude-haiku-4-5-20251001` | Claude Haiku 4.5 |
| `claude-haiku-4-5` | Alias for Claude Haiku 4.5 |

Short convenience aliases accepted by auth2api:

Expand All @@ -139,18 +140,30 @@ Short convenience aliases accepted by auth2api:

### Endpoints

| Endpoint | Description |
|----------|-------------|
| `POST /v1/chat/completions` | OpenAI-compatible chat |
| `POST /v1/responses` | OpenAI Responses API compatibility |
| `POST /v1/messages` | Claude native passthrough |
| `POST /v1/messages/count_tokens` | Claude token counting |
| `GET /v1/models` | List available models |
| `GET /admin/accounts` | Account health/status (API key required) |
| `GET /health` | Health check |
| Endpoint | Description |
| -------------------------------- | ---------------------------------------- |
| `POST /v1/chat/completions` | OpenAI-compatible chat |
| `POST /v1/responses` | OpenAI Responses API compatibility |
| `POST /v1/messages` | Claude native passthrough |
| `POST /v1/messages/count_tokens` | Claude token counting |
| `GET /v1/models` | List available models |
| `GET /admin/accounts` | Account health/status (API key required) |
| `GET /health` | Health check |

## Docker

### Quick start (prebuilt image)

Prebuilt images are published to GitHub Container Registry from the default branch:

```bash
docker pull ghcr.io/AmazingAng/auth2api:latest
```

Pull requests only build the image for verification and do not publish packages.

### Build from source

```bash
# Build
docker build -t auth2api .
Expand All @@ -163,7 +176,7 @@ docker run -d \
auth2api
```

Or with docker-compose:
Or use docker-compose:

```bash
docker-compose up -d
Expand Down
57 changes: 35 additions & 22 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ node dist/index.js
复制 `config.example.yaml` 为 `config.yaml`,然后按需修改:

```yaml
host: "" # 绑定地址,空字符串表示 127.0.0.1
host: "" # 绑定地址,空字符串表示 127.0.0.1
port: 8317

auth-dir: "~/.auth2api" # OAuth token 存储目录
auth-dir: "~/.auth2api" # OAuth token 存储目录

api-keys:
- "your-api-key-here" # 客户端使用这个 key 访问代理
- "your-api-key-here" # 客户端使用这个 key 访问代理

body-limit: "200mb" # 最大 JSON 请求体大小,适合大上下文场景
body-limit: "200mb" # 最大 JSON 请求体大小,适合大上下文场景

cloaking:
mode: "auto" # auto | always | never
mode: "auto" # auto | always | never
strict-mode: false
sensitive-words: []
cache-user-id: false

debug: "off" # off | errors | verbose
debug: "off" # off | errors | verbose
```

如果你要跑较长的 Claude Code 任务,也可以单独配置上游超时:
Expand All @@ -103,6 +103,7 @@ timeouts:
默认请求体大小限制现在是 `200mb`,比之前固定的 `20mb` 更适合 Claude Code 的大上下文使用场景。

`debug` 现在支持三级日志:

- `off`:不输出额外调试日志
- `errors`:记录上游/网络失败信息和上游错误响应正文
- `verbose`:在 `errors` 基础上,再输出每个请求的方法、路径、状态码和耗时
Expand All @@ -124,12 +125,12 @@ curl http://127.0.0.1:8317/v1/chat/completions \

### 支持的模型

| 模型 ID | 说明 |
|--------|------|
| `claude-opus-4-6` | Claude Opus 4.6 |
| `claude-sonnet-4-6` | Claude Sonnet 4.6 |
| `claude-haiku-4-5-20251001` | Claude Haiku 4.5 |
| `claude-haiku-4-5` | Claude Haiku 4.5 的别名 |
| 模型 ID | 说明 |
| --------------------------- | ----------------------- |
| `claude-opus-4-6` | Claude Opus 4.6 |
| `claude-sonnet-4-6` | Claude Sonnet 4.6 |
| `claude-haiku-4-5-20251001` | Claude Haiku 4.5 |
| `claude-haiku-4-5` | Claude Haiku 4.5 的别名 |

auth2api 额外支持以下便捷别名:

Expand All @@ -139,18 +140,30 @@ auth2api 额外支持以下便捷别名:

### 接口列表

| Endpoint | 说明 |
|----------|------|
| `POST /v1/chat/completions` | OpenAI 兼容聊天接口 |
| `POST /v1/responses` | OpenAI Responses API 兼容接口 |
| `POST /v1/messages` | Claude 原生消息透传 |
| `POST /v1/messages/count_tokens` | Claude token 计数 |
| `GET /v1/models` | 列出可用模型 |
| `GET /admin/accounts` | 查看账号健康状态(需要 API key) |
| `GET /health` | 健康检查 |
| Endpoint | 说明 |
| -------------------------------- | -------------------------------- |
| `POST /v1/chat/completions` | OpenAI 兼容聊天接口 |
| `POST /v1/responses` | OpenAI Responses API 兼容接口 |
| `POST /v1/messages` | Claude 原生消息透传 |
| `POST /v1/messages/count_tokens` | Claude token 计数 |
| `GET /v1/models` | 列出可用模型 |
| `GET /admin/accounts` | 查看账号健康状态(需要 API key) |
| `GET /health` | 健康检查 |

## Docker

### 快速开始(预构建镜像)

默认分支会发布预构建镜像到 GitHub Container Registry:

```bash
docker pull ghcr.io/AmazingAng/auth2api:latest
```

拉取请求只会构建镜像用于校验,不会发布包。

### 从源码构建

```bash
# 构建
docker build -t auth2api .
Expand All @@ -163,7 +176,7 @@ docker run -d \
auth2api
```

或者使用 docker-compose:
或使用 docker-compose:

```bash
docker-compose up -d
Expand Down