platform-models-api-configure
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSalesforce Models API setup for an AI coding agent
为AI编码Agent配置Salesforce Models API
The Salesforce Models API () is
authenticated with a signed OrgJWT (obtained via with
the scope — see ; no proxy). That auth and the
base URL are the same for any agent. How each agent then talks to the
endpoint is agent-specific: Anthropic clients (Claude Code and the Claude
Agent SDK) route through Bedrock mode (the env vars in Step 3), whereas
other agents (e.g. Codex) use their own client config against the same endpoint
and token — Bedrock mode does not apply to them.
https://api.salesforce.com/ai/gpt/v1client_credentialssfap_apiscripts/get-orgjwt.shThe steps below are the Claude Code / Claude Agent SDK reference
implementation (Bedrock mode + a JSON settings file + an API-key helper). For
a non-Bedrock agent, reuse the OrgJWT auth (Step 1) and the base URL, and apply
the equivalent client settings in that agent's own config location instead of
the Bedrock env vars.
Bundled scripts are in . Path placeholders below: = the
absolute path to this skill's own directory (the folder containing this
; resolve it from the skill path in context). = the absolute
path to the user's project root. Always emit fully resolved absolute paths —
the API-key helper runs from an undefined working directory, so relative paths
break it.
scripts/<SKILL>SKILL.md<ABS>Salesforce Models API()通过签名的OrgJWT进行认证(通过带有权限范围的获取——详见;无需代理)。该认证方式和基础URL对所有Agent都适用。不同Agent与端点通信的方式则因Agent而异:Anthropic客户端(Claude Code和Claude Agent SDK)通过Bedrock模式(步骤3中的环境变量)进行路由,而其他Agent(如Codex)则使用自身的客户端配置对接相同的端点和令牌——Bedrock模式不适用于这些Agent。
https://api.salesforce.com/ai/gpt/v1sfap_apiclient_credentialsscripts/get-orgjwt.sh以下步骤是Claude Code/Claude Agent SDK的参考实现(Bedrock模式 + JSON配置文件 + API密钥助手)。对于非Bedrock模式的Agent,请复用OrgJWT认证(步骤1)和基础URL,并在该Agent自身的配置位置应用等效的客户端设置,而非使用Bedrock环境变量。
配套脚本位于目录下。以下路径占位符说明: = 本技能自身目录的绝对路径(包含此的文件夹;根据上下文的技能路径解析)。 = 用户项目根目录的绝对路径。请始终输出完全解析的绝对路径——API密钥助手的运行工作目录不确定,因此相对路径会导致运行失败。
scripts/<SKILL>SKILL.md<ABS>Prerequisite
前置条件
A connected app in the org with the OAuth scope and the
client_credentials flow enabled (consumer key/secret + a run-as user).
Setup steps: https://developer.salesforce.com/docs/ai/agentforce/guide/access-models-api-with-rest.html
+ installed.
sfap_apicurljq组织中已创建Connected App,且具备**OAuth权限范围,并启用了client_credentials**流程(包含消费者密钥/密钥对 + 运行用户)。设置步骤:https://developer.salesforce.com/docs/ai/agentforce/guide/access-models-api-with-rest.html
已安装 + 工具。
sfap_apicurljqInputs to collect
需要收集的输入信息
- — org My Domain, e.g.
SF_INSTANCE_URLhttps://acme.my.salesforce.com - ,
SF_CLIENT_ID— connected-app consumer key/secretSF_CLIENT_SECRET - Models API base URL:
https://api.salesforce.com/ai/gpt/v1 - Model: a fully qualified name, e.g.
sfdc_ai__…(full list: https://developer.salesforce.com/docs/ai/agentforce/guide/supported-models.html)sfdc_ai__DefaultBedrockAnthropicClaude46Sonnet - Scope: project (, default) or user (
<cwd>/.claude/settings.json) — reference-agent settings paths~/.claude/settings.json - Headers — =
<FEAT>(defaultx-client-feature-id),ai-platform-models-connected-app=<APP>(defaultx-sfdc-app-context). Used in the Step 2 verify curl and inEinsteinGPT.ANTHROPIC_CUSTOM_HEADERS
- — 组织My Domain,例如
SF_INSTANCE_URLhttps://acme.my.salesforce.com - ,
SF_CLIENT_ID— Connected App的消费者密钥/密钥对SF_CLIENT_SECRET - Models API基础URL:
https://api.salesforce.com/ai/gpt/v1 - 模型:完整限定的名称,例如
sfdc_ai__…(完整列表:https://developer.salesforce.com/docs/ai/agentforce/guide/supported-models.html)sfdc_ai__DefaultBedrockAnthropicClaude46Sonnet - 范围:项目级(,默认)或用户级(
<cwd>/.claude/settings.json)——参考Agent的配置文件路径~/.claude/settings.json - 请求头 — =
<FEAT>(默认值x-client-feature-id),ai-platform-models-connected-app=<APP>(默认值x-sfdc-app-context)。用于步骤2的验证curl命令和EinsteinGPT中。ANTHROPIC_CUSTOM_HEADERS
Steps (reference implementation)
步骤(参考实现)
Concrete values for a JSON-settings + API-key-helper agent. Reuse the OrgJWT
auth, verify curl, and base URL verbatim for any agent; adapt the settings-file
location and env-var wiring to the target agent.
- Write (chmod 600), gitignore it:
<project>/.claude/.orgjwt.enviniSF_INSTANCE_URL="..." SF_CLIENT_ID="..." SF_CLIENT_SECRET="..." - Verify — must return before writing settings:
200bashTOKEN=$(bash <SKILL>/scripts/get-orgjwt.sh <ABS>/.claude/.orgjwt.env) curl -s -o /dev/null -w '%{http_code}\n' \ <MODELS_API_URL>/model/<MODEL>/invoke-with-response-stream \ -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \ -H 'x-client-feature-id: <FEAT>' -H 'x-sfdc-app-context: <APP>' \ --data '{"anthropic_version":"bedrock-2023-05-31","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}' - Write (merge into existing; keep other keys):
.claude/settings.jsonUse absolute paths injson{ "apiKeyHelper": "bash <SKILL>/scripts/get-orgjwt.sh <ABS>/.claude/.orgjwt.env", "model": "<MODEL>", "env": { "ANTHROPIC_AUTH_TOKEN": "", "CLAUDE_CODE_USE_BEDROCK": "1", "CLAUDE_CODE_SKIP_BEDROCK_AUTH": "1", "ANTHROPIC_BEDROCK_BASE_URL": "<MODELS_API_URL>", "ANTHROPIC_SMALL_FAST_MODEL": "<MODEL>", "ANTHROPIC_DEFAULT_MODEL": "<MODEL>", "ANTHROPIC_CUSTOM_HEADERS": "x-client-feature-id: <FEAT>\nx-sfdc-app-context: <APP>" } }. (apiKeyHelper/<FEAT>defaults are in "Inputs to collect" above.)<APP> - Tell the admin to fully restart the agent (for the reference agent) — settings and the API-key helper load at startup only.
claude
适用于JSON配置 + API密钥助手类型Agent的具体配置值。对于任何Agent,请直接复用OrgJWT认证、验证curl命令和基础URL;根据目标Agent调整配置文件位置和环境变量设置。
- 创建文件(设置权限为chmod 600),并添加至git忽略列表:
<project>/.claude/.orgjwt.enviniSF_INSTANCE_URL="..." SF_CLIENT_ID="..." SF_CLIENT_SECRET="..." - 验证配置——在写入配置文件前,必须返回状态码:
200bashTOKEN=$(bash <SKILL>/scripts/get-orgjwt.sh <ABS>/.claude/.orgjwt.env) curl -s -o /dev/null -w '%{http_code}\n' \ <MODELS_API_URL>/model/<MODEL>/invoke-with-response-stream \ -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \ -H 'x-client-feature-id: <FEAT>' -H 'x-sfdc-app-context: <APP>' \ --data '{"anthropic_version":"bedrock-2023-05-31","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}' - 写入文件(与现有内容合并;保留其他键):
.claude/settings.json在json{ "apiKeyHelper": "bash <SKILL>/scripts/get-orgjwt.sh <ABS>/.claude/.orgjwt.env", "model": "<MODEL>", "env": { "ANTHROPIC_AUTH_TOKEN": "", "CLAUDE_CODE_USE_BEDROCK": "1", "CLAUDE_CODE_SKIP_BEDROCK_AUTH": "1", "ANTHROPIC_BEDROCK_BASE_URL": "<MODELS_API_URL>", "ANTHROPIC_SMALL_FAST_MODEL": "<MODEL>", "ANTHROPIC_DEFAULT_MODEL": "<MODEL>", "ANTHROPIC_CUSTOM_HEADERS": "x-client-feature-id: <FEAT>\nx-sfdc-app-context: <APP>" } }中使用绝对路径。(apiKeyHelper/<FEAT>的默认值见上方“需要收集的输入信息”部分。)<APP> - 告知管理员完全重启Agent(参考Agent使用命令)——配置文件和API密钥助手仅在启动时加载。
claude
Capturing as a runbook (when asked to document, not apply)
整理为运行手册(当用户要求文档记录而非直接应用时)
If the user wants the setup written up for review instead of applied to their
machine (e.g. "save it as a Markdown runbook"), write all of the above into
the requested file (e.g. ), in order and self-contained:
the exact contents, the + gitignore note, the
verification curl (with the "must be before writing settings" note), the
full block with every key from Step 3, and the final
"fully restart " step. Don't omit any of the nine keys.
models-api-setup-runbook.md.orgjwt.envchmod 600200settings.jsonclaudesettings.json如果用户希望将配置步骤整理为文档供审核,而非直接应用到机器上(例如“保存为Markdown运行手册”),请将上述所有内容按顺序写入请求的文件(例如),内容需独立完整:包括的准确内容、及git忽略的说明、验证curl命令(附带“写入配置文件前必须返回状态码”的说明)、步骤3中的完整代码块,以及最后“完全重启”的步骤。请勿省略中的9个键。
models-api-setup-runbook.md.orgjwt.envchmod 600200settings.jsonclaudesettings.jsonVerify before finishing
完成前的验证项
- created,
.claude/.orgjwt.env, and gitignoredchmod 600 - Verification curl returned HTTP before
200was writtensettings.json - set to
ANTHROPIC_AUTH_TOKENin""settings.json - set to
CLAUDE_CODE_USE_BEDROCK"1" - set to
CLAUDE_CODE_SKIP_BEDROCK_AUTH"1" - is exactly
ANTHROPIC_BEDROCK_BASE_URL(no trailing slash/path)https://api.salesforce.com/ai/gpt/v1 - ,
model, andANTHROPIC_DEFAULT_MODELall use the fully qualifiedANTHROPIC_SMALL_FAST_MODELaliassfdc_ai__… - contains
ANTHROPIC_CUSTOM_HEADERSandx-client-feature-idx-sfdc-app-context - uses absolute paths (
apiKeyHelper)bash <SKILL>/scripts/get-orgjwt.sh <ABS>/.claude/.orgjwt.env - User told to fully restart
claude
- 已创建文件,设置了
.claude/.orgjwt.env权限,并添加至git忽略列表chmod 600 - 验证curl命令在写入前返回了HTTP
settings.json状态码200 - 中的
settings.json已设置为ANTHROPIC_AUTH_TOKEN"" - 已设置为
CLAUDE_CODE_USE_BEDROCK"1" - 已设置为
CLAUDE_CODE_SKIP_BEDROCK_AUTH"1" - 完全等于
ANTHROPIC_BEDROCK_BASE_URL(无末尾斜杠/路径)https://api.salesforce.com/ai/gpt/v1 - 、
model和ANTHROPIC_DEFAULT_MODEL均使用完整限定的ANTHROPIC_SMALL_FAST_MODEL别名sfdc_ai__… - 包含
ANTHROPIC_CUSTOM_HEADERS和x-client-feature-idx-sfdc-app-context - 使用了绝对路径(
apiKeyHelper)bash <SKILL>/scripts/get-orgjwt.sh <ABS>/.claude/.orgjwt.env - 已告知用户完全重启
claude
Must be exact (each prevents a specific failure)
必须严格执行(每项可避免特定故障)
- — clears any global token that would otherwise outrank
"ANTHROPIC_AUTH_TOKEN": ""(precedence:apiKeyHelper>ANTHROPIC_AUTH_TOKENANTHROPIC_API_KEY). Without it → wrong/old bearer → 401/404.apiKeyHelper - — activates the Bedrock API client; without it Claude Code uses the standard Anthropic API protocol and ignores
CLAUDE_CODE_USE_BEDROCK=1entirely, so every call bypasses the Models API.ANTHROPIC_BEDROCK_BASE_URL - — else Claude Code overwrites
CLAUDE_CODE_SKIP_BEDROCK_AUTH=1with AWS SigV4 and the OrgJWT never lands.Authorization - must be invoked as
apiKeyHelper(avoids exit-126).bash <path> <credsfile> - Model must be a fully qualified name (see supported models).
sfdc_ai__… - Auth is the OrgJWT from (a signed JWT, 2 dots, scope
client_credentials) — NOTsfap_api(unsigned session token → 404).sf org displayCLI has no client_credentials command; the helper callssf./services/oauth2/token - Only routes; no tenant-id header needed.
ANTHROPIC_BEDROCK_BASE_URL
- — 清除任何全局令牌,否则该令牌优先级会高于
"ANTHROPIC_AUTH_TOKEN": ""(优先级顺序:apiKeyHelper>ANTHROPIC_AUTH_TOKEN>ANTHROPIC_API_KEY)。若不设置此值→使用错误/旧的Bearer令牌→401/404错误。apiKeyHelper - — 激活Bedrock API客户端;若不设置,Claude Code会使用标准Anthropic API协议,完全忽略
CLAUDE_CODE_USE_BEDROCK=1,导致所有请求绕过Models API。ANTHROPIC_BEDROCK_BASE_URL - — 否则Claude Code会用AWS SigV4覆盖
CLAUDE_CODE_SKIP_BEDROCK_AUTH=1请求头,导致OrgJWT无法生效。Authorization - 必须以
apiKeyHelper的形式调用(避免exit-126错误)。bash <path> <credsfile> - 模型必须使用完整限定的名称(详见支持的模型列表)。
sfdc_ai__… - 认证使用的是来自的OrgJWT(签名的JWT,包含2个点,权限范围为
client_credentials)——不是sfap_api获取的令牌(未签名的会话令牌→404错误)。sf org displayCLI没有client_credentials命令;助手脚本调用sf获取令牌。/services/oauth2/token - 仅可用于路由;无需租户ID请求头。
ANTHROPIC_BEDROCK_BASE_URL
Diagnose
故障诊断
| Error | Meaning | Check first |
|---|---|---|
| Token is not a valid OrgJWT | Connected App |
| Token valid but model/env/org not routable | Fully qualified |
| Non-alias model id | Replace with a fully qualified |
| 错误 | 含义 | 优先检查项 |
|---|---|---|
| 令牌不是有效的OrgJWT | Connected App是否具备 |
| 令牌有效,但模型/环境/组织无法路由 | 是否使用了完整限定的 |
| 使用了非别名的模型ID | 替换为完整限定的 |