platform-models-api-configure
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSalesforce Models API setup for an AI coding agent
面向AI编码代理的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对任何代理都是通用的。不同代理与端点通信的方式则因代理而异:Anthropic客户端(Claude Code和Claude Agent SDK)通过Bedrock模式(步骤3中的环境变量)路由,而其他代理(如Codex)则使用自身的客户端配置连接同一端点并使用相同令牌——Bedrock模式不适用于这些代理。
https://api.salesforce.com/ai/gpt/v1sfap_apiclient_credentialsscripts/get-orgjwt.sh以下步骤是Claude Code/Claude Agent SDK的参考实现(Bedrock模式 + JSON设置文件 + API密钥助手)。对于非Bedrock模式的代理,请复用OrgJWT认证(步骤1)和基础URL,然后在该代理自身的配置位置应用等效的客户端设置,而非使用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— 连接应用的消费者密钥/密码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)——参考代理的设置路径~/.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密钥助手代理的具体配置值。对于任何代理,请直接复用OrgJWT认证、验证curl命令和基础URL;根据目标代理调整设置文件位置和环境变量配置。
- 写入文件(设置权限为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> - 告知管理员完全重启代理(参考代理为)——设置和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 | 连接应用的 |
| 令牌有效,但模型/环境/组织无法路由 | 是否使用了完全限定的 |
| 使用了非别名的模型ID | 替换为完全限定的 |