﻿---
title: "通过 TrueFoundry 连接模型服务"
filename: "~/.codex/truefoundry.config.toml"
canonical: /templates/truefoundry-codex-gateway/
---

# 通过 TrueFoundry 连接模型服务

用户层 [model_providers.truefoundry]，SaaS base_url 是 https://gateway.truefoundry.ai，wire_api = responses。env_key 读 TFY_API_KEY，不要把 Bearer 写进 http_headers。

```
export TFY_API_KEY=YOUR_TFY_API_KEY

# ~/.codex/config.toml
[model_providers.truefoundry]
name = "TrueFoundry AI Gateway"
base_url = "https://gateway.truefoundry.ai"
env_key = "TFY_API_KEY"
wire_api = "responses"

# ~/.codex/truefoundry.config.toml
model_provider = "truefoundry"
model = "gpt-5.2-codex"

codex --profile truefoundry

# 自建：base_url 写成 Playground 里的字面量，不要在 URL 里写 $GATEWAY_BASE_URL
# ChatGPT 订阅：不要 env_key；requires_openai_auth = true
# env_http_headers = { "x-tfy-api-key" = "TFY_API_KEY" }

# 不要：
# [model_providers.truefoundry.http_headers]
# Authorization = "Bearer YOUR_TFY_API_KEY"
# wire_api = "chat"
# [profiles.truefoundry]
# openai_base_url = "https://gateway.truefoundry.ai"
# model = "openai-main/gpt-5.2-codex"
# plugin add truefoundry@

```
