How is7qin/c3api works
c3api is a self-hosted AI gateway with an embedded admin and user console. Clients send requests through the HTTP server; the proxy authenticates and gates AI traffic, obtains scheduler-selected upstream attempts, forwards supported protocols, and records usage for billing and statistics. Admin and user APIs expose account, template, routing, rules, pricing, and usage management. The README documents the broader capabilities; several worker and integration links below are therefore documented relationships rather than inspected call sites.
Main entry points: repository Repositories · pipeline.go AI proxy pipeline · server.go HTTP server · routing_view.go Plan selection
Components 19
HTTP and consoles
- HTTP server
internal/server/server.go - Web console
web/src/App.tsx - API handlers
internal/handler - Admin services
internal/service/service.go
AI gateway
- AI proxy pipeline
internal/proxy/pipeline.go - Protocol forwarding
internal/proxy
Routing and rules
- Plan selection
internal/scheduler/routing_view.go - Routing compiler
internal/scheduler/routing_compiler_wire.go - Routing management
internal/service/routing.go - Rules engine
internal/rule/engine.go
Usage and operations
- Quality observation
internal/quality - Billing and usage
internal/billing - Pricing sync
internal/pricing/worker.go - Background workers
internal/worker/worker.go
Persistence
- Repositories
internal/repository - PostgreSQL state
Other components
- SDKs and browser
- AI providers
- Redis coordination
Connections 25
- SDKs and browser → HTTP server: send requests
README.md - HTTP server → Web console: serves console
internal/server/server.go - Web console → HTTP server: calls API
README.md - HTTP server → API handlers: routes admin API
internal/server/server.go - API handlers → Admin services: invokes services
internal/handler/handler.go - HTTP server → AI proxy pipeline: routes AI traffic
internal/server/server.go - AI proxy pipeline → Plan selection: selects attempts
internal/proxy/pipeline.go - AI proxy pipeline → Rules engine: evaluates rules
internal/proxy/pipeline.go - AI proxy pipeline → Protocol forwarding: dispatches formats
README.md - Protocol forwarding → AI providers: forwards requests
README.md - AI proxy pipeline → Billing and usage: records usage
README.md - AI proxy pipeline → Quality observation: observes attempts
- Quality observation → Repositories: persists facts
- Routing compiler → Repositories: reads observations
- Routing compiler → Plan selection: publishes plans
README.md - Routing management → Repositories: manages routing data
internal/service/routing.go - Routing management → Plan selection: updates routing
internal/service/routing.go - Rules engine → Repositories: loads rules
internal/rule/engine.go - Admin services → Repositories: reads and writes
internal/service/service.go - Repositories → PostgreSQL state: queries state
internal/repository/routing_query.go - Billing and usage → Repositories: stores usage and balances
- Background workers → Pricing sync: runs sync worker
internal/pricing/worker.go - Pricing sync → Repositories: upserts prices
internal/pricing/worker.go - PostgreSQL state → HTTP server: publishes invalidations
README.md - Background workers → Redis coordination: coordinates instances
README.md