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

6.3 KiB

Troubleshooting

Sign-in fails

Check the absolute credential-file path, readable valid JSON, required fields, and current client-secret service-key values. Service bindings and certificate keys are not accepted. Use service roots without endpoint paths. See credentials.

Only supported SAP *.hana.ondemand.com service hosts are accepted. Other landscapes, embedded URL credentials, nondefault ports, or query/fragment components are rejected. Do not disable TLS verification to work around a trust failure.

No models appear or a model becomes unavailable

Check the credential file's resource group, RUNNING deployment status, scenario/executable, and model eligibility. GPT requires major version 6 or higher, not a fixed name or backend date. The active backend version must match the catalog and any configured version pin. For both GPT and Claude, latest is only a configuration selector: backend details must report a concrete version, even when the catalog includes a latest entry. Catalog availability alone does not mean a deployment exists. Unresolved, deprecated, or retired versions remain unavailable.

Discovery refreshes after its five-minute cache expires, including time spent in system sleep. Restart the gateway to rebuild immediately and wait for startup discovery to finish before sending requests. A retained visible host catalog is not proof that the deployment is still usable; dispatch checks the current registry.

Unsupported request parameters

Use the API request fields. Responses does not accept Chat fields directly. Supported reasoning effort is low/medium/high with optional automatic summary; none is unsupported. Use stateless history rather than a previous response ID. Preserve complete tool history and original call IDs.

For Claude, use /v1/messages and the native Messages fields, not Responses input. Enabled thinking requires a positive integer budget_tokens; adaptive/disabled thinking must omit it. Opus 4.8 active version 1 rejects temperature, top_p, and enabled thinking. Sonnet 4.6 active version 1 accepts either sampling setting individually, not both, and rejects enabled thinking with forced tool use. Both baseline versions enforce max_tokens <= 128000. Newer versions do not inherit these limits or model-specific restrictions. Unknown request/tool fields fail explicitly; only the documented boolean pi tool hints are consumed during adaptation.

Claude streaming requires explicit support on the matched catalog version; omitted support does not authorize streaming. A stream must include a valid message start and stop-reason delta before its stop frame. An identity-resolution error means non-empty catalog identity metadata was unrecognized or conflicted; an explicit non-Anthropic provider cannot qualify through a Claude name substring.

Credential updates and multiple accounts

Sign in again after changing credentials and restart other running gateways. Reauthorization in another process cannot revoke an already-running host's in-memory account generation at an identical file path. Deleting/recreating a file at that path is not an automatic rotation signal.

Use the displayed account label to pin requests; see account selection. Do not guess a selector from a hash or send SAP credentials as the gateway key.

First request after overnight sleep returns discovery 401

discovery-response with HTTP 401 means an AI Core discovery endpoint rejected the request before inference; it does not establish an OAuth client-secret refusal. Older plugin versions used only a monotonic expiry clock, which pauses during system sleep in Bun on macOS and could retain yesterday's expired token. Token reuse now checks wall-clock deadlines as well.

Fully quit and reopen the Magpie app, or restart the gateway process, to load the fixed plugin and discard the old in-memory token. Restarting pi alone does not reset the gateway's token. Do not rotate credentials based on this error alone. If discovery still returns 401 with a fresh token, check the service-key/API landscape pairing and account access.

Error handling

  • Verified OAuth client refusal expires the affected sign-in.
  • Discovery/inference 401 keeps sign-in; verified invalid/expired Bearer rejection discards the token for a subsequent independent operation, without replaying the failed generation in the plugin.
  • 404 can mean the selected model/deployment is unavailable.
  • 429 may mean tenant/resource-group quota or backend capacity. Numeric-seconds Retry-After is preserved when supplied; the status alone does not identify the cause.
  • Temporary upstream failures, timeouts, and cancellation remain errors rather than successful empty replies.
  • An HTTP 200 stream may still fail or end incomplete. Native failure events and missing/malformed terminals must not be interpreted as completion.
  • Long active streams no longer hit the former two-minute total cutoff: defaults are 120 seconds idle and 900 seconds total. inference-idle-timeout means no stream chunk was relayed within the idle window; inference-timeout means the total cap or pre-stream deadline expired. See timeout options. Magpie may wrap either stream-read failure as "connection lost mid-reply"; that wording alone does not establish an AI Core network outage.

Error descriptions are credential-redacted; native identities, output history, status, and error categories are retained. Magpie may retry or fail over independently. Do not assume one client request means exactly one billed generation.

Cancellation and host constraints

Local abort stops owned HTTP/body delivery but does not prove SAP backend termination or billing cessation. Independent requests can continue after another request is cancelled.

Host initialization hooks do not supply a caller abort signal; they have internal deadlines. On cold fetch, the host may initialize credentials/discovery before the plugin sees and rejects an unsafe request URL. Cancelling sign-in after authorization does not necessarily prevent the host saving the successful account. These constraints do not authorize unsafe inference routing or stale-registry dispatch.

Back to setup