forcedotcom/sf-skills

platform-models-api-configure

Configure (or troubleshoot) an AI coding agent or CLI to route through the Salesforce Models API using a signed OrgJWT.

View source
Original skill document

Rendered from the source repository. Headings, examples, code, tables, links, and referenced images are preserved.

Salesforce Models API setup for an AI coding agent

The Salesforce Models API (https://api.salesforce.com/ai/gpt/v1) is authenticated with a signed OrgJWT (obtained via client_credentials with the sfap_api scope — see scripts/get-orgjwt.sh; 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.

The 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 scripts/. Path placeholders below: <SKILL> = the absolute path to this skill's own directory (the folder containing this SKILL.md; resolve it from the skill path in context). <ABS> = 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.

Prerequisite

A connected app in the org with the `sfap_api` 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 curl + jq installed.

Inputs to collect

  • SF_INSTANCE_URL — org My Domain, e.g. https://acme.my.salesforce.com
  • SF_CLIENT_ID, SF_CLIENT_SECRET — connected-app consumer key/secret
  • Models API base URL: https://api.salesforce.com/ai/gpt/v1
  • Model: a fully qualified sfdc_ai__… name, e.g.

sfdc_ai__DefaultBedrockAnthropicClaude46Sonnet (full list: https://developer.salesforce.com/docs/ai/agentforce/guide/supported-models.html)

  • Scope: project (<cwd>/.claude/settings.json, default) or user (~/.claude/settings.json) — reference-agent settings paths
  • Headers — <FEAT> = x-client-feature-id (default ai-platform-models-connected-app),

<APP> = x-sfdc-app-context (default EinsteinGPT). Used in the Step 2 verify curl and in 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.

  1. Write <project>/.claude/.orgjwt.env (chmod 600), gitignore it:
ini
   SF_INSTANCE_URL="..."
   SF_CLIENT_ID="..."
   SF_CLIENT_SECRET="..."
  1. Verify — must return 200 before writing settings:
bash
   TOKEN=$(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"}]}'
  1. Write .claude/settings.json (merge into existing; keep other keys):
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>"
     }
   }

Use absolute paths in apiKeyHelper. (<FEAT> / <APP> defaults are in "Inputs to collect" above.)

  1. Tell the admin to fully restart the agent (claude for the reference agent) —

settings and the API-key helper load at startup only.

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. models-api-setup-runbook.md), in order and self-contained: the exact .orgjwt.env contents, the chmod 600 + gitignore note, the verification curl (with the "must be 200 before writing settings" note), the full settings.json block with every key from Step 3, and the final "fully restart claude" step. Don't omit any of the nine settings.json keys.

Verify before finishing

  • [ ] .claude/.orgjwt.env created, chmod 600, and gitignored
  • [ ] Verification curl returned HTTP 200 before settings.json was written
  • [ ] ANTHROPIC_AUTH_TOKEN set to "" in settings.json
  • [ ] CLAUDE_CODE_USE_BEDROCK set to "1"
  • [ ] CLAUDE_CODE_SKIP_BEDROCK_AUTH set to "1"
  • [ ] ANTHROPIC_BEDROCK_BASE_URL is exactly https://api.salesforce.com/ai/gpt/v1 (no trailing slash/path)
  • [ ] model, ANTHROPIC_DEFAULT_MODEL, and ANTHROPIC_SMALL_FAST_MODEL all use the fully qualified sfdc_ai__… alias
  • [ ] ANTHROPIC_CUSTOM_HEADERS contains x-client-feature-id and x-sfdc-app-context
  • [ ] apiKeyHelper uses absolute paths (bash <SKILL>/scripts/get-orgjwt.sh <ABS>/.claude/.orgjwt.env)
  • [ ] User told to fully restart claude

Must be exact (each prevents a specific failure)

  • "ANTHROPIC_AUTH_TOKEN": "" — clears any global token that would otherwise

outrank apiKeyHelper (precedence: ANTHROPIC_AUTH_TOKEN > ANTHROPIC_API_KEY

apiKeyHelper). Without it → wrong/old bearer → 401/404.
  • CLAUDE_CODE_USE_BEDROCK=1 — activates the Bedrock API client; without it

Claude Code uses the standard Anthropic API protocol and ignores ANTHROPIC_BEDROCK_BASE_URL entirely, so every call bypasses the Models API.

  • CLAUDE_CODE_SKIP_BEDROCK_AUTH=1 — else Claude Code overwrites Authorization

with AWS SigV4 and the OrgJWT never lands.

  • apiKeyHelper must be invoked as bash <path> <credsfile> (avoids exit-126).
  • Model must be a fully qualified sfdc_ai__… name (see supported models).
  • Auth is the OrgJWT from client_credentials (a signed JWT, 2 dots, scope

sfap_api) — NOT sf org display (unsigned session token → 404). sf CLI has no client_credentials command; the helper calls /services/oauth2/token.

  • Only ANTHROPIC_BEDROCK_BASE_URL routes; no tenant-id header needed.

Diagnose

ErrorMeaningCheck first
401Token is not a valid OrgJWTConnected App sfap_api scope, client_credentials flow enabled, consumer key/secret in .orgjwt.env; ANTHROPIC_AUTH_TOKEN not cleared to ""
404Token valid but model/env/org not routableFully qualified sfdc_ai__… model alias, ANTHROPIC_BEDROCK_BASE_URL exactly https://api.salesforce.com/ai/gpt/v1, org entitled for the Models API, ANTHROPIC_AUTH_TOKEN cleared
model not availableNon-alias model idReplace with a fully qualified sfdc_ai__… alias (see supported models)
from this repository

More skills

All skills
forcedotcom
Community

agentforce-d360-analyze

Data Cloud 360° view of a single Agentforce session. TRIGGER when user asks to trace, inspect, summarize, or describe a specific Agentforce session by session id (Agent Session UUID 019d… or MessagingSession id 0Mw…). Also triggers on session discovery — find/list/search sessions by time, agent, channel, outcome, or conversation text — when the user has no session id yet. DO NOT TRIGGER for design-time architecture questions (use agentforce-architecture-analyze instead) or for runtime perf/latency/SLO questions that require platform telemetry beyond Data Cloud.

installs
1
GitHub stars
972
Updated
Sep 7
forcedotcom
Community

agentforce-generate

Build, modify, audit, repair, optimize, debug, and deploy agents with Agentforce Agent Script. TRIGGER when: user creates, reviews, or changes .agent files or aiAuthoringBundle metadata; asks to fix AgentScript, audit an existing agent, run an AgentScript health check, common-pitfall review, or baseline-versus-candidate repair loop; changes a response, action, subagent, route, state flow, or Agent Spec; previews, debugs, deploys, publishes, or tests agents; uses sf agent generate/preview/publish/test; or manages Agentforce MCP servers, tools, assets, or authentication. DO NOT TRIGGER when: Apex, Flow, Prompt Template, Experience Cloud, or general Salesforce CLI work is unrelated to Agent Script; or the primary input is a production session or trace ID rather than an agent artifact.

installs
1
GitHub stars
972
Updated
Sep 7
forcedotcom
Community

platform-quick-deploy

Deploy validated metadata to a Production Salesforce org without re-running tests. TRIGGER when the user wants to deploy to production, says 'quick deploy', 'promote', 'ship to prod', or has just validated and wants to push the change live. REQUIRES a recent sf project deploy validate job ID (≤10 days old, ≤3 days for --use-most-recent). DO NOT TRIGGER for sandbox/scratch deploys (use platform-metadata-deploy) or unvalidated deploys (use platform-deploy-validate first).

installs
1
GitHub stars
972
Updated
Sep 7
forcedotcom
Community

agentforce-test

Write, run, and analyze structured test suites for Agentforce agents — functional AND security. TRIGGER when: user writes or modifies test spec YAML (AiEvaluationDefinition); runs sf agent test create, run, run-eval, or results commands; asks about test coverage strategy, metric selection, or custom evaluations; interprets test results or diagnoses test failures; asks about batch testing, regression suites, or CI/CD test integration; requests security testing, OWASP LLM Top 10, red-teaming, penetration testing, prompt-injection tests, a security grade, or a vulnerability assessment of an agent. DO NOT TRIGGER when: user creates, modifies, previews, or debugs .agent files (use agentforce-generate); deploys or publishes agents; writes Agent Script code; uses sf agent preview for development iteration; analyzes production session traces (use agentforce-observe); performs a static safety review of .agent file content (use agentforce-generate Section 15).

installs
3
GitHub stars
972
Updated
Sep 7