AI Gateway Integration
Estimated reading time: 7 minutes 预计阅读时间: 7 分钟Summerrs Admin can serve as the admin backend foundation for an AI gateway. It provides login authentication, RBAC, menu buttons, resource permissions, dictionaries, operation logs, and MCP tools that can support AI channels, models, API keys, usage, audit, and operations.
An AI gateway usually has two parts:
Admin APIs fit naturally into the /api system, reusing admin JWTs, button permissions, resource permissions, and ApiResult responses. Relay protocol entrypoints should be mounted as a separate route group, such as /v1/chat/completions, /v1/messages, and /v1beta/models/*, with API keys, model routing, streaming responses, and protocol-specific error models.
Reusable Admin Capabilities
The AI gateway admin side can reuse Summerrs Admin infrastructure:
This lets the AI module focus on model-gateway domain logic while the admin foundation stays consistent with the rest of the system.
Recommended Module Boundaries
AI admin APIs and relay protocol entrypoints have different auth, error, and response models. Keep the modules clear:
The main app can register both admin and relay plugins:
Design the two entrypoint families separately:
This prevents admin login state, button permissions, API keys, streaming responses, and third-party protocol errors from being mixed into one request chain.
Admin Features
An AI admin backend usually includes these pages:
Admin handlers can follow the existing system style:
Menu buttons can be organized by business object:
If you want the resource-permission layer to apply, register AI admin APIs in sys.resource and bind them to the corresponding Button through sys.action_resource. You can reload the policy with:
API Key Auth
Relay callers are programs, external applications, or agents. Use a dedicated API key strategy instead of admin JWTs.
Common request format:
An API key should contain at least:
The auth flow can be:
Show only key prefixes/suffixes in the admin UI. Return the plaintext key only once at creation time, then replace it through rotation.
Model Routing
Model routing maps client-requested models to actual upstreams:
Common routing dimensions:
Write the routing result into request logs so operators can answer "which model did the client request, and which upstream did it actually hit?"
Streaming Responses
LLM relays often return SSE or chunked bodies. Streaming differs from normal admin JSON:
Continue using #[log] for admin actions. Relay requests should write to a dedicated AI request log, for example:
This keeps admin operation audit intact while giving relay traffic the high-frequency, streaming, billing-oriented log model it needs.
Rate Limits And Quotas
summer-common::rate_limit provides #[rate_limit], RateLimitEngine, and cost-based rate limiting. Admin APIs can use declarative limits; relay traffic is better controlled by API key and token cost.
For LLM requests, reserve quota before calling the upstream:
Common strategies:
If the API key is in Authorization, the relay auth layer can parse it first, then call RateLimitContext with the resolved token identifier.
Relationship To MCP
MCP and AI relay solve different problems:
MCP can help develop AI admin modules: generate entities, CRUD, frontend bundles, then plan menus and dictionaries with menu_tool and dict_tool. Relay handles online model calls, API keys, quotas, routing, logs, and streaming responses.
Integration Checklist
You can integrate an AI gateway module in this order:
- Define AI domain models: channels, models, API keys, routing rules, request logs, usage stats.
- Create admin menus and button permissions with the
ai:*permission namespace. - Add admin APIs with
#[log],#[has_perm], and resource-permission bindings. - Design API key auth: store only hashes and show plaintext only once.
- Implement model routing from client model names to real upstream channels.
- Add rate limits and quotas for keys, tenants, models, and token cost.
- Create dedicated request logs for streaming responses, final status, and usage.
- Use MCP to generate or validate CRUD, menus, dictionaries, and frontend page drafts.
This lets the AI gateway fit into the admin system while keeping relay protocol entrypoints independent.
