truefoundry-gateway
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<objective>Routing note: For ambiguous user intents, use the shared clarification templates in references/intent-clarification.md.
<objective>路由说明:对于模糊的用户意图,请使用references/intent-clarification.md中的共享澄清模板。
Gateway
网关
Configure and operate TrueFoundry's AI Gateway: unified OpenAI-compatible LLM access, provider account integrations, content safety guardrails, and request monitoring/observability.
配置并操作TrueFoundry的AI Gateway:统一的OpenAI兼容LLM访问、服务商账户集成、内容安全防护,以及请求监控与可观测性。
When to Use
使用场景
- Access LLMs through TrueFoundry's unified OpenAI-compatible gateway
- Configure auth tokens (PAT/VAT), rate limiting, budget controls, or load balancing across providers
- List, create, or manage LLM provider accounts (OpenAI, AWS Bedrock, Google Vertex, Azure, Groq, Together AI, custom OpenAI-compatible endpoints, self-hosted models, etc.)
- Set up guardrail providers, create guardrail rules, or manage content safety policies (PII filtering, content moderation, prompt injection detection, secret detection, custom validation)
- Investigate gateway traffic: recent requests, cost breakdowns, error rates, model usage, per-user activity, MCP tool calls, or latency analysis
- 通过TrueFoundry的统一OpenAI兼容网关访问LLM
- 配置认证令牌(PAT/VAT)、速率限制、预算控制,或跨服务商的负载均衡
- 列出、创建或管理LLM服务商账户(OpenAI、AWS Bedrock、Google Vertex、Azure、Groq、Together AI、自定义OpenAI兼容端点、自托管模型等)
- 设置防护服务商、创建防护规则,或管理内容安全策略(PII过滤、内容审核、提示注入检测、密钥检测、自定义验证)
- 分析网关流量:近期请求、成本明细、错误率、模型使用情况、单用户活动、MCP工具调用或延迟分析
When NOT to Use
非使用场景
- User wants to deploy a self-hosted model -> deploying self-hosted models requires a TrueFoundry Enterprise account with a connected cluster. See https://truefoundry.com
- User wants to deploy tool servers -> deploying workloads requires a TrueFoundry Enterprise account with a connected cluster. See https://truefoundry.com
- User wants to manage TrueFoundry platform credentials -> prefer skill (Status Check section)
platform - User wants to manage MCP servers (tool servers) -> prefer skill
mcp-servers - User wants to manage platform secrets directly -> prefer skill (Secrets section)
platform - User wants to instrument their own application with tracing -> prefer skill
observability - User wants to view application container logs -> prefer skill
observability
- 用户想要部署自托管模型 -> 部署自托管模型需要带有已连接集群的TrueFoundry企业账户。请查看https://truefoundry.com
- 用户想要部署工具服务器 -> 部署工作负载需要带有已连接集群的TrueFoundry企业账户。请查看https://truefoundry.com
- 用户想要管理TrueFoundry平台凭据 -> 优先使用技能(状态检查章节)
platform - 用户想要管理MCP服务器(工具服务器) -> 优先使用技能
mcp-servers - 用户想要直接管理平台密钥 -> 优先使用技能(密钥章节)
platform - 用户想要为自己的应用添加追踪功能 -> 优先使用技能
observability - 用户想要查看应用容器日志 -> 优先使用技能
observability
Deploying a Custom Guardrails Server
部署自定义防护服务器
Start from the official template: truefoundry/custom-guardrails-template. Build on top of it, then deploy.
</objective>
<context>从官方模板开始:truefoundry/custom-guardrails-template。在其基础上构建,然后部署。
</objective>
<context>Overview
概述
Your App -> AI Gateway -> OpenAI / Anthropic / Azure / Self-hosted vLLM / etc.
^
Unified API + Auth + Rate Limiting + Routing + LoggingKey benefits: Single endpoint for all models, one API key (PAT/VAT), OpenAI-compatible, rate limiting, budget controls, load balancing with fallback, guardrails, and full observability.
Your App -> AI Gateway -> OpenAI / Anthropic / Azure / Self-hosted vLLM / etc.
^
Unified API + Auth + Rate Limiting + Routing + Logging核心优势: 所有模型共用一个端点、一个API密钥(PAT/VAT)、兼容OpenAI、速率限制、预算控制、带降级的负载均衡、防护机制,以及完整的可观测性。
Gateway Endpoint
网关端点
{TFY_BASE_URL}/api/llm{TFY_BASE_URL}/api/llmAuthentication
认证
PAT (Personal Access Token): Dashboard -> Access -> Personal Access Tokens. For development.
VAT (Virtual Access Token): Dashboard -> Access -> Virtual Account Tokens. For production (not tied to a user, supports granular model access).
</context>
<instructions>PAT(个人访问令牌): 控制台 -> 访问权限 -> 个人访问令牌。适用于开发场景。
VAT(虚拟账户令牌): 控制台 -> 访问权限 -> 虚拟账户令牌。适用于生产环境(不绑定用户,支持精细化模型访问)。
</context>
<instructions>Security Policy
安全策略
- All credentials in manifests MUST use references, never raw values.
tfy-secret:// - Never ask the user to paste an API key into chat. Direct them to store it in TrueFoundry dashboard -> Secrets, then provide only the URI. Or have them set it via
tfy-secret://so it stays in the shell.! export TFY_API_KEY=... - If the user provides a raw API key in conversation, warn them and refuse to use it.
- 清单中的所有凭据必须使用引用,绝对不能使用原始值。
tfy-secret:// - 绝对不要要求用户在聊天中粘贴API密钥。 引导他们将密钥存储在TrueFoundry控制台 -> 密钥中,然后仅提供URI。或者让他们通过
tfy-secret://设置,使其保留在Shell中。! export TFY_API_KEY=... - 如果用户在对话中提供了原始API密钥,需向其发出警告并拒绝使用。
Preflight
预检
Verify is complete. If missing, stop and use .
tfy logintruefoundry-onboardSet for direct API calls:
TFY_API_SHbash
TFY_API_SH=~/.claude/skills/truefoundry-gateway/scripts/tfy-api.sh确认已完成。如果未完成,请停止操作并使用。
tfy logintruefoundry-onboard为直接API调用设置:
TFY_API_SHbash
TFY_API_SH=~/.claude/skills/truefoundry-gateway/scripts/tfy-api.shQuick Lookups — One Call, One Answer
快速查询 — 一次调用,一个答案
For read-only questions, go straight to the API. Do not explore CLI subcommands — they don't exist. See references/cli-reference.md.
| User asks | Single call |
|---|---|
| What models/providers are attached? | |
| What models can I call? | |
| What guardrails are configured? | |
| Show recent gateway requests | |
| Is the gateway reachable? | |
After login is confirmed, the next step for any read question is the API call above — nothing else.
对于只读问题,直接调用API。不要尝试CLI子命令——它们不存在。请查看references/cli-reference.md。
| 用户问题 | 单次调用 |
|---|---|
| 当前已关联哪些模型/服务商? | |
| 我可以调用哪些模型? | |
| 已配置哪些防护机制? | |
| 显示近期网关请求 | |
| 网关是否可达? | |
确认登录后,所有只读问题的下一步都是调用上述API——无需其他操作。
Calling Models
调用模型
The gateway is OpenAI-compatible. Minimal example:
bash
curl "${TFY_BASE_URL}/api/llm/chat/completions" \
-H "Authorization: Bearer ${TFY_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"model": "openai/gpt-4o", "messages": [{"role": "user", "content": "Hello!"}], "max_tokens": 200}'Or set environment variables for any OpenAI SDK:
bash
export OPENAI_BASE_URL="${TFY_BASE_URL}/api/llm"
export OPENAI_API_KEY="<your-PAT-or-VAT>"For complete SDK examples (Python, Node.js, streaming), supported APIs table, framework integrations (LangChain, LlamaIndex, Cursor), and routing/rate-limiting/budget configuration, see references/calling-models.md.
网关兼容OpenAI。最简示例:
bash
curl "${TFY_BASE_URL}/api/llm/chat/completions" \
-H "Authorization: Bearer ${TFY_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"model": "openai/gpt-4o", "messages": [{"role": "user", "content": "Hello!"}], "max_tokens": 200}'或者为任意OpenAI SDK设置环境变量:
bash
export OPENAI_BASE_URL="${TFY_BASE_URL}/api/llm"
export OPENAI_API_KEY="<your-PAT-or-VAT>"完整的SDK示例(Python、Node.js、流式传输)、支持的API表格、框架集成(LangChain、LlamaIndex、Cursor)以及路由/速率限制/预算配置,请查看references/calling-models.md。
Provider Integrations
服务商集成
List Provider Accounts
列出服务商账户
bash
$TFY_API_SH GET /api/svc/v1/provider-accountsPresent as a formatted table with name, provider, type, and model count (from array length).
integrationsbash
$TFY_API_SH GET /api/svc/v1/provider-accounts以格式化表格展示,包含名称、服务商、类型和模型数量(取自数组长度)。
integrationsCreate Provider Account
创建服务商账户
- Ensure credentials are stored as TrueFoundry secrets first (skill, Secrets section)
platform - Use the appropriate provider template from references/provider-templates.md
- Apply:
$TFY_API_SH POST /api/svc/v1/provider-accounts "$payload"
Supported providers: OpenAI, AWS Bedrock, Google Vertex, Azure OpenAI, Groq, Together AI, Custom (any OpenAI-compatible), Self-Hosted, TrueFoundry.
- 确保凭据已先存储为TrueFoundry密钥(技能,密钥章节)
platform - 使用references/provider-templates.md中的对应服务商模板
- 应用:
$TFY_API_SH POST /api/svc/v1/provider-accounts "$payload"
支持的服务商:OpenAI、AWS Bedrock、Google Vertex、Azure OpenAI、Groq、Together AI、自定义(任意OpenAI兼容)、自托管、TrueFoundry。
Applying Config (Any Gateway Resource)
应用配置(任意网关资源)
bash
tfy apply -f manifest.yaml --dry-run --show-diff
tfy apply -f manifest.yamlDo NOT delegate gateway applies to a deployment skill. Gateway configs are applied inline with .
tfy applybash
tfy apply -f manifest.yaml --dry-run --show-diff
tfy apply -f manifest.yaml不要将网关配置应用委托给部署技能。网关配置需通过直接应用。
tfy applyGuardrails
防护机制
Guardrails add content safety controls. Setup requires two steps:
- Create guardrail config group — register provider integrations
- Create gateway guardrails config — create rules referencing those providers
Quick list:
$TFY_API_SH GET /api/svc/v1/gateway-guardrails-configsFor full setup instructions, rule structure, API calls, and common patterns, see references/guardrails-setup.md.
Supported providers reference: references/guardrail-providers.md.
防护机制可添加内容安全控制。设置分为两步:
- 创建防护配置组 — 注册服务商集成
- 创建网关防护配置 — 创建引用这些服务商的规则
快速列出:
$TFY_API_SH GET /api/svc/v1/gateway-guardrails-configs完整的设置说明、规则结构、API调用和常见模式,请查看references/guardrails-setup.md。
支持的服务商参考:references/guardrail-providers.md。
AI Monitoring
AI监控
Query gateway request traces via the spans API and aggregate usage via the metrics API. Requires either or for trace queries; suggest as a starting point when the user does not know the destination.
tracingProjectFqndataRoutingDestination"default"通过spans API查询网关请求追踪,通过metrics API汇总使用情况。追踪查询需要或;当用户不知道目标时,建议使用作为起始值。
tracingProjectFqndataRoutingDestination"default"Recent Requests
近期请求
bash
$TFY_API_SH POST /api/svc/v1/spans/query '{
"dataRoutingDestination": "default",
"startTime": "2026-05-15T00:00:00.000Z",
"limit": 20,
"sortDirection": "desc"
}'Present results as formatted tables (time, model, status, tokens, cost, latency, user).
For all monitoring use cases (cost analysis, errors, model usage, user filtering, MCP tool calls, metadata filtering), filter types, response structure, and pagination, see references/monitoring.md.
bash
$TFY_API_SH POST /api/svc/v1/spans/query '{
"dataRoutingDestination": "default",
"startTime": "2026-05-15T00:00:00.000Z",
"limit": 20,
"sortDirection": "desc"
}'以格式化表格展示结果(时间、模型、状态、令牌数、成本、延迟、用户)。
所有监控用例(成本分析、错误、模型使用情况、用户过滤、MCP工具调用、元数据过滤)、过滤类型、响应结构和分页,请查看references/monitoring.md。
Aggregated Metrics
汇总指标
Use this path for aggregate questions such as:
- "Show cost incurred for the last 3 months."
- "Break cost down by model, user, team, or virtual account."
- "Show total tokens and latency by model."
- "Which virtual account generated the most cost?"
bash
$TFY_API_SH POST /api/svc/v1/llm-gateway/metrics/query '{
"startTs": "...", "endTs": "...",
"datasource": "modelMetrics",
"type": "distribution",
"aggregations": [{"type": "sum", "column": "costInUSD"}],
"groupBy": ["modelName"]
}'When answering a time-range question, calculate exact and , state the range used, and present totals in a compact table. If the user asks for monthly breakdowns, run one query per month unless the API exposes a time-bucket field.
startTsendTs以下汇总类问题可使用此路径:
- "显示过去3个月产生的成本。"
- "按模型、用户、团队或虚拟账户拆分成本。"
- "按模型显示总令牌数和延迟。"
- "哪个虚拟账户产生的成本最高?"
bash
$TFY_API_SH POST /api/svc/v1/llm-gateway/metrics/query '{
"startTs": "...", "endTs": "...",
"datasource": "modelMetrics",
"type": "distribution",
"aggregations": [{"type": "sum", "column": "costInUSD"}],
"groupBy": ["modelName"]
}'回答时间范围问题时,需计算精确的和,说明使用的范围,并以简洁表格展示总计。如果用户要求月度细分,除非API提供时间桶字段,否则需每月运行一次查询。
startTsendTsGenerating Manifests
生成清单
For any gateway entity or policy:
- Fetch existing config — API call from Quick Lookups
- Consult schema reference — see table below
- Generate YAML — use for credentials
tfy-secret:// - Validate —
tfy apply -f manifest.yaml --dry-run --show-diff - Apply —
tfy apply -f manifest.yaml
| Entity | Reference |
|---|---|
| Provider accounts | references/provider-templates.md |
| Virtual models / routing | references/calling-models.md (Virtual Models section) |
| Rate limiting | references/schemas/rate-limiting.md |
| Budget controls | references/schemas/budget-limiting.md |
| Guardrails | references/guardrails-setup.md |
| Observability tables | references/observability.md |
<success_criteria>
对于任意网关实体或策略:
- 获取现有配置 — 调用快速查询中的API
- 参考架构文档 — 见下表
- 生成YAML — 凭据使用
tfy-secret:// - 验证 —
tfy apply -f manifest.yaml --dry-run --show-diff - 应用 —
tfy apply -f manifest.yaml
| 实体 | 参考文档 |
|---|---|
| 服务商账户 | references/provider-templates.md |
| 虚拟模型/路由 | references/calling-models.md(虚拟模型章节) |
| 速率限制 | references/schemas/rate-limiting.md |
| 预算控制 | references/schemas/budget-limiting.md |
| 防护机制 | references/guardrails-setup.md |
| 可观测性表格 | references/observability.md |
<success_criteria>
Success Criteria
成功标准
AI Gateway
AI网关
- User can call LLMs through the gateway using OpenAI-compatible SDK or cURL
- Valid PAT or VAT configured
- Target model name confirmed available
- Working code snippets provided in user's language/framework
- 用户可通过兼容OpenAI的SDK或cURL通过网关调用LLM
- 已配置有效的PAT或VAT
- 确认目标模型名称可用
- 提供适用于用户语言/框架的可运行代码片段
Provider Integrations
服务商集成
- Provider accounts listed in a formatted table
- New provider accounts use for all credentials
tfy-secret:// - Provider type and model details confirmed before creating
- 服务商账户以格式化表格列出
- 新服务商账户的所有凭据均使用
tfy-secret:// - 创建前确认服务商类型和模型详情
Guardrails
防护机制
- Guardrail config groups listed
- Rules correctly target intended models, users, and tools
- Create/update operations confirmed before executing
- 防护配置组已列出
- 规则正确指向目标模型、用户和工具
- 执行前确认创建/更新操作
AI Monitoring
AI监控
- Recent traces shown with timestamps, models, status, costs
- Results presented as formatted tables, not raw JSON
- or
dataRoutingDestinationasked before queryingtracingProjectFqn
</success_criteria>
<references>- 显示包含时间戳、模型、状态、成本的近期追踪
- 结果以格式化表格展示,而非原始JSON
- 查询前询问或
dataRoutingDestinationtracingProjectFqn
</success_criteria>
<references>References
参考文档
Core
核心文档
- cli-reference.md — CLI commands, flags, what doesn't exist
- api-endpoints.md — Full REST API with curl examples
- cli-reference.md — CLI命令、标志、不存在的功能
- api-endpoints.md — 包含curl示例的完整REST API文档
Gateway Operations
网关操作
- calling-models.md — SDK examples, routing, rate limiting, budgets, frameworks
- provider-templates.md — All provider manifest templates (OpenAI, Bedrock, Vertex, Azure, etc.)
- guardrails-setup.md — Guardrail config groups and rules setup
- monitoring.md — Spans query API, metrics, use cases
- guardrail-providers.md — All 23 guardrail provider types
- calling-models.md — SDK示例、路由、速率限制、预算、框架
- provider-templates.md — 所有服务商清单模板(OpenAI、Bedrock、Vertex、Azure等)
- guardrails-setup.md — 防护配置组和规则设置
- monitoring.md — Spans查询API、指标、用例
- guardrail-providers.md — 全部23种防护服务商类型
Schemas
架构文档
- schemas/provider-account.md — Provider account schema
- schemas/virtual-model.md — Virtual model / load balancing schema
- schemas/rate-limiting.md — Rate limiting schema
- schemas/budget-limiting.md — Budget control schema
- schemas/guardrail-config.md — Guardrail config schema
- schemas/provider-account.md — 服务商账户架构
- schemas/virtual-model.md — 虚拟模型/负载均衡架构
- schemas/rate-limiting.md — 速率限制架构
- schemas/budget-limiting.md — 预算控制架构
- schemas/guardrail-config.md — 防护配置架构
Other
其他文档
- access-management.md — Identity, PAT/VAT, permissions
- integrations.md — Native SDK proxy, IDE integrations
- observability.md — SQL query patterns
- span-attributes.md — 60+ span attribute definitions
- access-management.md — 身份认证、PAT/VAT、权限
- integrations.md — 原生SDK代理、IDE集成
- observability.md — SQL查询模式
- span-attributes.md — 60+种span属性定义
Composability
组合性
- Store credentials first: skill (Secrets section) -> then
platformURItfy-secret:// - Need API key: Dashboard -> Access -> Personal Access Tokens or Virtual Accounts
- MCP servers: skill
mcp-servers - Deploy models: Requires TrueFoundry Enterprise with connected cluster
- Instrument your app: skill (Tracing section)
observability
- 先存储凭据:技能(密钥章节)-> 再使用
platformURItfy-secret:// - 需要API密钥:控制台 -> 访问权限 -> 个人访问令牌或虚拟账户
- MCP服务器:技能
mcp-servers - 部署模型:需要带有已连接集群的TrueFoundry企业账户
- 为应用添加监控:技能(追踪章节)
observability
Error Handling
错误处理
401 Unauthorized
401 未授权
API key (PAT/VAT) is invalid or expired. Check header.
Authorization: Bearer <token>API密钥(PAT/VAT)无效或已过期。检查请求头。
Authorization: Bearer <token>403 Forbidden
403 禁止访问
Token lacks access to this model. PATs inherit user permissions; VATs only access explicitly selected models.
令牌无权访问此模型。PAT继承用户权限;VAT仅能访问明确选中的模型。
404 Model Not Found
404 模型未找到
Model name not in gateway. Check exact name via dashboard -> AI Gateway -> Models or .
GET /api/llm/models模型名称不在网关中。通过控制台 -> AI Gateway -> 模型或检查准确名称。
GET /api/llm/models429 Rate Limited
429 速率受限
Wait and retry (check Retry-After header). Request higher limits or use load balancing.
等待并重试(检查Retry-After请求头)。申请更高限制或使用负载均衡。
502/503 Provider Error
502/503 服务商错误
Upstream provider issue. Gateway auto-retries/fallbacks if routing is configured. Check provider status page.
上游服务商问题。如果已配置路由,网关会自动重试/降级。请查看服务商状态页面。
Permission Denied (Provider Accounts)
权限拒绝(服务商账户)
User needs role. Check collaborators on the provider account.
provider-account-manager用户需要角色。检查服务商账户的协作者。
provider-account-managerInvalid Secret Reference
无效密钥引用
tfy-secret://tfy-secret://TENANT:SECRET_GROUP:SECRET_KEYplatformtfy-secret://tfy-secret://TENANT:SECRET_GROUP:SECRET_KEYplatformType Filter Not Working
类型过滤无效
The query parameter on does NOT filter. Fetch all and filter client-side.
typeGET /api/svc/v1/provider-accountsGET /api/svc/v1/provider-accountstypeProvider Account Name Already Exists
服务商账户名称已存在
Use a different name or update the existing account.
使用其他名称或更新现有账户。
Model Not Appearing in Gateway After Creation
创建后模型未出现在网关中
Verify: provider account created successfully, integration has correct , collaborators include or relevant users.
model_typesteam:everyone验证:服务商账户创建成功、集成的正确、协作者包含或相关用户。
model_typesteam:everyoneNo Monitoring Data
无监控数据
Check: time range is correct, exists, filters aren't too restrictive, gateway has received requests.
dataRoutingDestination检查:时间范围正确、存在、过滤条件不过于严格、网关已收到请求。
dataRoutingDestination400 Bad Request (Monitoring)
400 请求错误(监控)
Missing required parameter. Ensure you provide or , and a valid in ISO 8601.
</troubleshooting>tracingProjectFqndataRoutingDestinationstartTime缺少必填参数。确保提供或,以及符合ISO 8601格式的有效。
</troubleshooting>tracingProjectFqndataRoutingDestinationstartTime