How songquanpeng/one-api works
One API is an OpenAI-compatible gateway that fronts many model providers, alongside an account and operations dashboard. The principal request path accepts a client API call, routes and selects a configured channel, adapts the request for the provider, then returns a compatible response and accounts usage. The README also documents streaming, images, retries, token and channel controls, billing, redemptions, and several login methods. Wiring is inferred only where supported by the tree, README, or sampled code; unsampled subsystem internals are represented at their enclosing paths.
Main entry points: main.go Application data · controller Relay handlers · billing Usage billing · relay.go HTTP routing
Components 19
API gateway
- HTTP routing
router/relay.go - Relay handlers
relay/controller - Channel selection
middleware/distributor.go - Usage billing
relay/billing
Provider adapters
- Provider adapters
relay/adaptor
Management
- Management routes
router/api.go - Admin controllers
controller - Authentication
controller/auth - Token controls
controller/token.go - Channel controls
controller/channel.go - Redemptions
controller/redemption.go
State and billing
- Application data
model/main.go - Usage logs
model/log.go - Channel monitoring
monitor
User interfaces
- Admin dashboard
web/default/src/App.js - Web API client
web/default/src/helpers/api.js
Other components
- API client
- Model providers
- OAuth services
Connections 18
- API client → HTTP routing: sends request
- HTTP routing → Relay handlers: dispatches
- Relay handlers → Channel selection: selects channel
- Relay handlers → Provider adapters: invokes adapter
- Provider adapters → Model providers: calls provider
- Relay handlers → Usage billing: accounts usage
- Usage billing → Application data: reads pricing
- Usage billing → Usage logs: records usage
- Channel selection → Application data: reads channels
- Admin dashboard → Web API client: calls API
- Web API client → Management routes: sends requests
- Management routes → Admin controllers: dispatches
- Admin controllers → Application data: reads and writes
- Authentication → OAuth services: delegates login
- Token controls → Application data: manages tokens
- Channel controls → Application data: manages channels
- Redemptions → Application data: manages codes
- Channel monitoring → Application data: tracks channels