功能简介
LLM Gateway 从 Project 已配置且启用的 Provider 汇总 Model Catalog,并按 model ID 路由 chat、embedding、rerank 或兼容 message 请求。Gateway Key、allowedModels、Scope、速率/预算与用量记录共同约束调用;模型实际可用性取决于 Provider。
当前支持范围
- Models 与 LLM Gateway(APPBASE_ENHANCED):统一发现已配置 Provider 的模型及 chat、embedding、rerank 能力,并用项目 Scope、Gateway Key 与用量记录约束调用。
适用场景
- 为应用统一发现可用模型及能力。
- 让多个 Provider 通过同一 Project API 接入。
- 为 Knowledge Base 和 Memory 选择 embedding/rerank/chat 模型。
前置条件
- Console 已配置至少一个 active Provider。
- 目标模型出现在
/llm-gateway/models。 - 调用身份具备相应 llm-gateway Scope 或有效 Gateway Key。
Console 操作路径
Console → Project → LLM Gateway。Providers 配置连接与模型,Keys 管理 Gateway Key 和 allowedModels,Usage 查看 Token/模型用量。Provider Secret 只在受保护表单输入。
SDK 示例
SDK · TypeScript
import { Client } from 'appbase-web-sdk';
const client = new Client()
.setEndpoint('https://<APPBASE_HOST>/v1')
.setProject('<PROJECT_ID>');
import { LlmGateway } from 'appbase-web-sdk';
const gateway = new LlmGateway(client);
const models = await gateway.listModels();
const response = await gateway.createChatCompletion({
model: '<MODEL_ID>',
messages: [{ role: 'user', content: 'Summarize the supplied context.' }],
maxTokens: 256,
stream: false
});
void [models, response];REST 示例
REST · Bash
curl 'https://<APPBASE_HOST>/v1/llm-gateway/chat/completions' \
-X POST \
-H 'X-Appwrite-Project: <PROJECT_ID>' \
-H 'X-Appwrite-Key: <GATEWAY_KEY>' \
-H 'Content-Type: application/json' \
--data '{"model":"<MODEL_ID>","messages":[{"role":"user","content":"Summarize the supplied context."}],"maxTokens":256,"stream":false}'常见错误
| 现象 | 处理建议 |
|---|---|
403 GENERAL_ACCESS_FORBIDDEN | Gateway Key 未允许该 model,或 Scope 不足。 |
| model/provider not found | 确认 Model Catalog、Provider 状态和能力类型。 |
| upstream timeout/unavailable | 按幂等性决定是否退避重试,并记录 Provider 健康。 |
| budget/rate limit | 更换有权限的 Key、等待窗口或调整受控预算。 |
当前限制
- AppBase 不训练模型、不托管权重,也不管理推理集群生命周期。
- BYOK 与存储 Provider Key 是不同信任模式,均不得写入日志。
- 模型名称存在不保证上游配额、区域或网络可用。
Appwrite 兼容说明
本页仅参考上游 AI/Tooling 分类;模型路由、Gateway Key 与接口细节来自 AppBase 实现。
AppBase 增强说明
AppBase 提供 Provider/Model Catalog、chat/embedding/rerank、Gateway Key 与用量控制,可作为知识、记忆和 Agent 应用的统一模型入口。
发布状态和验证 Commit
origin/main 已核验。验证 Commit:0363062a1c7ea08741975bb5ba0c3361663c9353。
权威来源文件列表
backend-candidate:src/Appwrite/Platform/Modules/LLMGateway/Http/LLMGateway/Chat/Completions/Create.phpbackend-candidate:src/Appwrite/Platform/Modules/LLMGateway/Http/LLMGateway/Models/backend-candidate:tests/e2e/Services/LLMGateway/LLMGatewayCustomClientTest.phpfrontend-candidate:console/src/routes/(console)/project-[region]-[project]/llm-gateway/
Appwrite taxonomy 仅作信息架构参考:https://appwrite.io/docs/tooling/ai。上游页面不是 AppBase 实现证据。