truefoundry-gateway

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Routing note: For ambiguous user intents, use the shared clarification templates in references/intent-clarification.md.
<objective>
路由说明:对于模糊的用户意图,请使用references/intent-clarification.md中的共享澄清模板。
<objective>

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
    platform
    skill (Status Check section)
  • User wants to manage MCP servers (tool servers) -> prefer
    mcp-servers
    skill
  • User wants to manage platform secrets directly -> prefer
    platform
    skill (Secrets section)
  • User wants to instrument their own application with tracing -> prefer
    observability
    skill
  • User wants to view application container logs -> prefer
    observability
    skill
  • 用户想要部署自托管模型 -> 部署自托管模型需要带有已连接集群的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 + Logging
Key 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/llm

Authentication

认证

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
    tfy-secret://
    references, never raw values.
  • Never ask the user to paste an API key into chat. Direct them to store it in TrueFoundry dashboard -> Secrets, then provide only the
    tfy-secret://
    URI. Or have them set it via
    ! export TFY_API_KEY=...
    so it stays in the shell.
  • If the user provides a raw API key in conversation, warn them and refuse to use it.
  • 清单中的所有凭据必须使用
    tfy-secret://
    引用,绝对不能使用原始值。
  • 绝对不要要求用户在聊天中粘贴API密钥。 引导他们将密钥存储在TrueFoundry控制台 -> 密钥中,然后仅提供
    tfy-secret://
    URI。或者让他们通过
    ! export TFY_API_KEY=...
    设置,使其保留在Shell中。
  • 如果用户在对话中提供了原始API密钥,需向其发出警告并拒绝使用。

Preflight

预检

Verify
tfy login
is complete. If missing, stop and use
truefoundry-onboard
.
Set
TFY_API_SH
for direct API calls:
bash
TFY_API_SH=~/.claude/skills/truefoundry-gateway/scripts/tfy-api.sh
确认
tfy login
已完成。如果未完成,请停止操作并使用
truefoundry-onboard
为直接API调用设置
TFY_API_SH
bash
TFY_API_SH=~/.claude/skills/truefoundry-gateway/scripts/tfy-api.sh

Quick 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 asksSingle call
What models/providers are attached?
$TFY_API_SH GET /api/svc/v1/provider-accounts
What models can I call?
curl -s "${TFY_BASE_URL}/api/llm/models" -H "Authorization: Bearer ${TFY_API_KEY}"
What guardrails are configured?
$TFY_API_SH GET /api/svc/v1/gateway-guardrails-configs
Show recent gateway requests
$TFY_API_SH POST /api/svc/v1/spans/query '{"startTime":"...","dataRoutingDestination":"default","limit":20,"sortDirection":"desc"}'
Is the gateway reachable?
curl -s "${TFY_BASE_URL}/api/llm/health"
After login is confirmed, the next step for any read question is the API call above — nothing else.

对于只读问题,直接调用API。不要尝试CLI子命令——它们不存在。请查看references/cli-reference.md
用户问题单次调用
当前已关联哪些模型/服务商?
$TFY_API_SH GET /api/svc/v1/provider-accounts
我可以调用哪些模型?
curl -s "${TFY_BASE_URL}/api/llm/models" -H "Authorization: Bearer ${TFY_API_KEY}"
已配置哪些防护机制?
$TFY_API_SH GET /api/svc/v1/gateway-guardrails-configs
显示近期网关请求
$TFY_API_SH POST /api/svc/v1/spans/query '{"startTime":"...","dataRoutingDestination":"default","limit":20,"sortDirection":"desc"}'
网关是否可达?
curl -s "${TFY_BASE_URL}/api/llm/health"
确认登录后,所有只读问题的下一步都是调用上述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-accounts
Present as a formatted table with name, provider, type, and model count (from
integrations
array length).
bash
$TFY_API_SH GET /api/svc/v1/provider-accounts
以格式化表格展示,包含名称、服务商、类型和模型数量(取自
integrations
数组长度)。

Create Provider Account

创建服务商账户

  1. Ensure credentials are stored as TrueFoundry secrets first (
    platform
    skill, Secrets section)
  2. Use the appropriate provider template from references/provider-templates.md
  3. 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.
  1. 确保凭据已先存储为TrueFoundry密钥(
    platform
    技能,密钥章节)
  2. 使用references/provider-templates.md中的对应服务商模板
  3. 应用:
    $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.yaml
Do NOT delegate gateway applies to a deployment skill. Gateway configs are applied inline with
tfy apply
.

bash
tfy apply -f manifest.yaml --dry-run --show-diff
tfy apply -f manifest.yaml
不要将网关配置应用委托给部署技能。网关配置需通过
tfy apply
直接应用。

Guardrails

防护机制

Guardrails add content safety controls. Setup requires two steps:
  1. Create guardrail config group — register provider integrations
  2. Create gateway guardrails config — create rules referencing those providers
Quick list:
$TFY_API_SH GET /api/svc/v1/gateway-guardrails-configs
For full setup instructions, rule structure, API calls, and common patterns, see references/guardrails-setup.md.
Supported providers reference: references/guardrail-providers.md.

防护机制可添加内容安全控制。设置分为两步:
  1. 创建防护配置组 — 注册服务商集成
  2. 创建网关防护配置 — 创建引用这些服务商的规则
快速列出:
$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
tracingProjectFqn
or
dataRoutingDestination
for trace queries; suggest
"default"
as a starting point when the user does not know the destination.
通过spans API查询网关请求追踪,通过metrics API汇总使用情况。追踪查询需要
tracingProjectFqn
dataRoutingDestination
;当用户不知道目标时,建议使用
"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
startTs
and
endTs
, 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.

以下汇总类问题可使用此路径:
  • "显示过去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"]
}'
回答时间范围问题时,需计算精确的
startTs
endTs
,说明使用的范围,并以简洁表格展示总计。如果用户要求月度细分,除非API提供时间桶字段,否则需每月运行一次查询。

Generating Manifests

生成清单

For any gateway entity or policy:
  1. Fetch existing config — API call from Quick Lookups
  2. Consult schema reference — see table below
  3. Generate YAML — use
    tfy-secret://
    for credentials
  4. Validate
    tfy apply -f manifest.yaml --dry-run --show-diff
  5. Apply
    tfy apply -f manifest.yaml
EntityReference
Provider accountsreferences/provider-templates.md
Virtual models / routingreferences/calling-models.md (Virtual Models section)
Rate limitingreferences/schemas/rate-limiting.md
Budget controlsreferences/schemas/budget-limiting.md
Guardrailsreferences/guardrails-setup.md
Observability tablesreferences/observability.md
</instructions>
<success_criteria>
对于任意网关实体或策略:
  1. 获取现有配置 — 调用快速查询中的API
  2. 参考架构文档 — 见下表
  3. 生成YAML — 凭据使用
    tfy-secret://
  4. 验证
    tfy apply -f manifest.yaml --dry-run --show-diff
  5. 应用
    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
</instructions>
<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
    tfy-secret://
    for all credentials
  • 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
  • dataRoutingDestination
    or
    tracingProjectFqn
    asked before querying
</success_criteria>
<references>
  • 显示包含时间戳、模型、状态、成本的近期追踪
  • 结果以格式化表格展示,而非原始JSON
  • 查询前询问
    dataRoutingDestination
    tracingProjectFqn
</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:
    platform
    skill (Secrets section) -> then
    tfy-secret://
    URI
  • Need API key: Dashboard -> Access -> Personal Access Tokens or Virtual Accounts
  • MCP servers:
    mcp-servers
    skill
  • Deploy models: Requires TrueFoundry Enterprise with connected cluster
  • Instrument your app:
    observability
    skill (Tracing section)
</references> <troubleshooting>
  • 先存储凭据
    platform
    技能(密钥章节)-> 再使用
    tfy-secret://
    URI
  • 需要API密钥:控制台 -> 访问权限 -> 个人访问令牌或虚拟账户
  • MCP服务器
    mcp-servers
    技能
  • 部署模型:需要带有已连接集群的TrueFoundry企业账户
  • 为应用添加监控
    observability
    技能(追踪章节)
</references> <troubleshooting>

Error Handling

错误处理

401 Unauthorized

401 未授权

API key (PAT/VAT) is invalid or expired. Check
Authorization: Bearer <token>
header.
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/models
检查准确名称。

429 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
provider-account-manager
role. Check collaborators on the provider account.
用户需要
provider-account-manager
角色。检查服务商账户的协作者。

Invalid Secret Reference

无效密钥引用

tfy-secret://
path cannot resolve. Verify format:
tfy-secret://TENANT:SECRET_GROUP:SECRET_KEY
. Use
platform
skill to check secret group exists.
tfy-secret://
路径无法解析。验证格式:
tfy-secret://TENANT:SECRET_GROUP:SECRET_KEY
。使用
platform
技能检查密钥组是否存在。

Type Filter Not Working

类型过滤无效

The
type
query parameter on
GET /api/svc/v1/provider-accounts
does NOT filter. Fetch all and filter client-side.
GET /api/svc/v1/provider-accounts
type
查询参数无法过滤。需获取全部数据后在客户端过滤。

Provider 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
model_types
, collaborators include
team:everyone
or relevant users.
验证:服务商账户创建成功、集成的
model_types
正确、协作者包含
team:everyone
或相关用户。

No Monitoring Data

无监控数据

Check: time range is correct,
dataRoutingDestination
exists, filters aren't too restrictive, gateway has received requests.
检查:时间范围正确、
dataRoutingDestination
存在、过滤条件不过于严格、网关已收到请求。

400 Bad Request (Monitoring)

400 请求错误(监控)

Missing required parameter. Ensure you provide
tracingProjectFqn
or
dataRoutingDestination
, and a valid
startTime
in ISO 8601.
</troubleshooting>
缺少必填参数。确保提供
tracingProjectFqn
dataRoutingDestination
,以及符合ISO 8601格式的有效
startTime
</troubleshooting>