Skip to content

Latest commit

 

History

History
66 lines (50 loc) · 2.03 KB

File metadata and controls

66 lines (50 loc) · 2.03 KB

NEW-API.md — SOP for CLI Harness

What is New API?

An AI API gateway/proxy built with Go (Gin + GORM). Aggregates 40+ upstream AI providers (OpenAI, Claude, Gemini, Azure, AWS Bedrock, etc.) behind a unified API with user management, billing, rate limiting, and an admin dashboard.

Architecture

Backend: Go 1.22+, Gin, GORM v2
Frontend: React 18 + Vite + Semi Design
DB: SQLite / MySQL / PostgreSQL
Cache: Redis + in-memory
Auth: JWT + sessions + WebAuthn + OAuth

Layered: Router -> Controller -> Service -> Model

API Response Format

All API responses follow:

{"success": true/false, "message": "", "data": <payload>}

Paginated responses use:

{"page": 1, "page_size": 20, "total": 100, "items": [...]}

CLI Command Map

CLI Command Group API Route Group Auth Level
auth /api/user/login, /api/user/self Public / User
user /api/user/ Admin
channel /api/channel/ Admin
token /api/token/ User
model /api/models/, /api/pricing Admin / Public
log /api/log/ Admin / User
redemption /api/redemption/ Admin
option /api/option/ Root
group /api/group/ Admin
performance /api/performance/ Root
subscription /api/subscription/ User / Admin
deployment /api/deployments/ Admin
vendor /api/vendors/ Admin
data /api/data/ Admin / User
system /api/status, /api/notice Public

Session Persistence

Sessions stored in ~/.cli-anything/new-api/session.json (chmod 600). Contains: base_url, access_token, username, user_id, role.

Auth Flow

  1. auth login — POST /api/user/login with username/password
  2. If 2FA required, prompt for code → POST /api/user/login/2fa
  3. Save access token, fetch /api/user/self for role info
  4. All subsequent requests use Bearer token auth

Channel Types (Provider IDs)

See constant/channel_type.go — 37+ provider types including: OpenAI(1), Claude(14), Gemini(24), Azure(3), AWS(33), etc.