# aba2api **Repository Path**: vanlin/aba2api ## Basic Information - **Project Name**: aba2api - **Description**: 借鉴sub2api的精简版模型汇聚功能 - **Primary Language**: Go - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-29 - **Last Updated**: 2026-07-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # aba2api aba2api 是一个借鉴 sub2api 思路的精简版模型汇聚服务,用 Go 网关和轻量管理后台统一管理多组大模型上游账号,并向客户端提供 OpenAI / Anthropic 兼容接口。 第一版聚焦“够用、易部署、易理解”的核心能力: - MySQL 9.x 兼容持久化。 - 管理后台入口:`/server/#/login`。 - 默认管理员从 `go/appsettings.json` 初始化。 - 上游账号模式:`openai` 和 `claude`。 - 网关端点:`/v1/models`、`/v1/messages`、`/v1/messages/count_tokens`、`/v1/responses`、`/v1/chat/completions`。 - OpenAI 兼容上游可以归入 OpenAI 分组统一调度。 - 开启 `allow_messages_dispatch=1` 的 OpenAI 分组可接收 Anthropic 兼容 `/v1/messages` 请求,并转发到 OpenAI 上游 `/v1/responses` 或 `/v1/chat/completions`。 - Go handler/service 测试覆盖流式代理和 OpenAI/Anthropic 流转换。 ## Local Configuration Default database configuration: ```text host: 127.0.0.1 port: 13306 database: aba2api username: aba2api password: aba2api ``` The config file is `go/appsettings.json`. The default admin account is: ```text username: admin password: admin ``` Credentials and upstream API keys are stored in plaintext in this first version. ## Build And Smoke Test Run from the repository root: ```powershell .\scripts\smoke.ps1 ``` The script runs: ```powershell cd web if (!(Test-Path node_modules)) { npm ci } npm run build cd ..\go go test ./... go build -o bin\aba2api-server.exe .\cmd\server ``` ## Run Locally Start MySQL first, then run: ```powershell cd go .\bin\aba2api-server.exe appsettings.json ``` Health checks: ```powershell curl.exe http://127.0.0.1:5000/health curl.exe http://127.0.0.1:5000/api/v1/health ``` Open the admin UI: ```text http://127.0.0.1:5000/server/#/login ``` ## Gateway Usage Gateway API keys are managed in the admin UI and used as bearer tokens: ```powershell curl.exe -H "Authorization: Bearer " http://127.0.0.1:5000/v1/models ``` `/v1/models` returns `account_models.external_model`. During calls, aba2api resolves that external model back to `account_models.upstream_model` before forwarding upstream. This keeps vendor model-name collisions out of client configs. For Claude Code CLI calling an OpenAI group through `/v1/messages`: 1. Create a group with `mode=openai` and `allow_messages_dispatch=1`. 2. Create an account in that group with `mode=openai`. 3. Set account `upstream_mode` to `responses` or `chat_completions`. 4. Add model mappings such as `external_model=op_glm-5.2`, `upstream_model=glm-5.2`. 5. Bind an API key to the group. 6. Point the client at `http://127.0.0.1:5000` and call `/v1/messages`. ## Minimal Seed SQL Use direct SQL only for smoke verification. The admin UI is the normal path. ```sql INSERT INTO `groups` (name, mode, allow_messages_dispatch, enabled, remark, create_time, update_time) VALUES ('openai-dispatch', 'openai', 1, 1, NULL, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000); SET @group_id = LAST_INSERT_ID(); INSERT INTO accounts (group_id, name, mode, auth_type, base_url, api_key, oauth_json, proxy_id, upstream_mode, enabled, priority, remark, create_time, update_time) VALUES (@group_id, 'local-openai', 'openai', 'api_key', 'http://127.0.0.1:18080', '', NULL, NULL, 'responses', 1, 0, NULL, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000); SET @account_id = LAST_INSERT_ID(); INSERT INTO account_models (account_id, external_model, upstream_model, enabled, sort_order, remark, create_time, update_time) VALUES (@account_id, 'op_glm-5.2', 'glm-5.2', 1, 0, NULL, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000); INSERT INTO api_keys (name, `key`, enabled, remark, create_time, update_time) VALUES ('smoke-key', '', 1, NULL, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000); SET @api_key_id = LAST_INSERT_ID(); INSERT INTO api_key_groups (api_key_id, group_id, create_time) VALUES (@api_key_id, @group_id, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3))*1000); ``` Then verify: ```powershell curl.exe -H "Authorization: Bearer " http://127.0.0.1:5000/v1/models ``` Expected model id: `op_glm-5.2`.