Files
caikn 0daf0c7421 sap-aicore 0.3.0: a new provider for SAP AI Core's GPT Responses and Claude Messages deployments (caikn, #651)
A new provider package, @magpie-community/opencode-sap-aicore-auth 0.3.0
(packages/sap-aicore). It signs in from a local SAP AI Core client-secret
credential file, discovers the account's running GPT (Responses) and Claude
(Messages, Bedrock) deployments per resource group, and sends requests only to
https://*.authentication.*.hana.ondemand.com (token) and
https://api.ai.*.hana.ondemand.com (inference). Image input is gated per model
on the catalog's inputTypes. Also: the root README row, a registry.json entry,
.DS_Store in .gitignore, and scripts/check.mjs accepts an empty static model
list for a package whose provider.models hook is a function with the same id
(npm and the loader are still required).

Reviewed at head b44b3e1b68889c2a12bcaa37ad5d546a398bdde0, with main 9bba5fed
merged in locally, on a Mac mini (macOS, Bun 1.4.2), no real SAP account:
- bun test packages/sap-aicore scripts: 351 pass, 0 fail.
- bun scripts/check.mjs: every package ok, sap-aicore included.
- The two tests that reached the network at e955194 now use inputs root()
  really rejects (/oauth, /v1), and a new test stubs fetch and checks that
  /oauth/token and /v2 are accepted and the token is posted to
  <authUrl>/oauth/token once. plugin.test.js fails on any unstubbed fetch.
- Whole package under a preload that records every non-loopback fetch, connect
  and DNS lookup: 0 attempts (the preload caught a deliberate fetch to
  example.invalid, so it does record).
- Broken by hand: putting the e955194 inputs back turns the test red through
  the new guard; making root() keep the given path turns the new
  /oauth/token + /v2 test red; letting root() accept any path turns 3 URL
  tests red.
- Not tried: a real SAP AI Core account (the author's run record covers one
  GPT and one Claude turn, plain and with a tool call; no image turn).

The first version goes out through the dist branch (npm doesn't have the name).
2026-11-04 22:19:43 +08:00

3.7 KiB

Credentials and accounts

The plugin accepts a JSON credential file with authUrl, baseUrl, clientId, clientSecret, and resourceGroup. Every field must be a nonempty string. Sign in using an absolute file path; store the file outside the repository with mode 0600.

Service-key mapping

Create the file manually from an SAP AI Core client-secret service key:

Service-key field Credential-file field
url authUrl
serviceurls.AI_API_URL baseUrl
clientid clientId
clientsecret clientSecret
Your chosen existing resource group resourceGroup

Service-binding JSON and x.509 certificate service keys are not accepted. See SAP's Create a Service Key.

Field requirements

  • authUrl: HTTPS OAuth root on a supported *.authentication.<region>.hana.ondemand.com host, without /oauth/token.
  • baseUrl: HTTPS AI Core root on a supported api.ai.*.hana.ondemand.com host, without /v2.
  • URLs must not contain embedded credentials, nondefault ports, extra paths, query strings, or fragments.
  • clientId must not contain a colon. clientSecret must not contain a colon or control characters.
  • resourceGroup must identify the group used for both discovery and inference.

OAuth uses raw UTF-8 HTTP Basic authentication, form content type, and only grant_type=client_credentials in the form body. The plugin does not try alternate authentication encodings. See SAP's Use a Service Key.

Accounts and credential updates

magpie plugin login sap-aicore
magpie accounts sap-aicore --json

Sign in each credential-file path separately. Reusing the same normalized path replaces its account after successful authorization; different paths represent different accounts, even if their contents describe the same SAP identity.

After credential rotation, update your external file and sign in again. Credentials are loaded once per account generation, not watched continuously. Another running gateway does not observe cross-process reauthorization at the same file path; restart it to load the changed credentials.

To pin a gateway request, set X-Magpie-Account to the account's displayed user label from the account listing. Labels can look like API key …abcd. JavaScript Fetch headers require byte strings; encode a non-ASCII label with Buffer.from(label,"utf8").toString("latin1"). Magpie removes the pin header before SAP dispatch. A pinned request does not select another account in its place.

Persistence and token lifecycle

Magpie persists only API authentication type, an opaque key derived from the normalized credential-file path, and credential-file metadata. Client secrets and SAP tokens are not copied into the account store.

Tokens stay in account-scoped memory. Renewal is on demand 60 seconds before expiry, or halfway through short token lifetimes. Both monotonic elapsed time and wall-clock deadlines bound reuse: system sleep cannot extend a SAP token's lifetime, and a backward wall-clock adjustment cannot extend its monotonic lifetime. Concurrent callers share acquisition; cancelling one waiter does not cancel acquisition still needed by another. File reads and token exchanges have 15-second bounds.

Only verified OAuth client-credential refusal expires sign-in. Network errors, cancellation, timeouts, malformed responses, and discovery/inference failures do not by themselves expire the account. See error handling.

Back to setup