Files
plugins/packages/sap-aicore
我是一条没有名字的区 e7004d9354 inkstone 0.1.0: Intern InkStone (书生·端砚) Token Plan, browser sign-in, credit card and ink-* key chat (#775)
New package @magpie-community/opencode-inkstone-auth 0.1.0 for Intern
InkStone (书生·端砚, Shanghai AI Lab) Token Plan, provider id
`intern-inkstone`. Community package by yunwang2442-creator.

What it does:
- Browser sign-in (Edge/Chrome, its own profile under
  $XDG_CONFIG_HOME or ~/.config/magpie/inkstone-browser, or
  %LOCALAPPDATA%\magpie\inkstone-browser). The login window has no
  debugging port. A headless CDP read takes the uaa-token cookie, and the
  same read renews it silently later.
- Usage card: ink-credit balance, 5-hour and 7-day windows, credit packs.
- Chat: a pasted ink-* API key, or one the sign-in creates, named
  ink-<host4>-<acct4>-<rand4> (18 of the console's 20 characters). An
  idempotency clash (-15109) retries with a fresh name, up to three times.
  Pruning is on by default. It only touches this machine's and account's
  prefix, keeps the newest two and the key this sign-in created, and never
  deletes manual keys or keys of unknown age.
- Closing on Unix: SIGTERM, then SIGKILL only after a 15s grace. Leftover
  browsers are matched by --user-data-dir=<escaped profile>, and Windows
  uses .Contains().
- The login wait comes from an injected waitForLogin in tests. No env
  hook is left in production code.
- Hosts: discovery.intern-ai.org.cn, discovery-api.intern-ai.org.cn,
  127.0.0.1 (CDP).

Outside the package: scripts/opencode2.mjs lets a prompt with
`required: false` stay optional (`p.required !== false`). Every package's
copy is synced byte for byte, so all 39 copies in the merged tree are blob
afe074cb. No other package sets `required: false` on a prompt, so this
changes nothing for them. Also a root README row and a registry entry.

Review at 36412a15, on mote, HOME=$(mktemp -d), Bun 1.4.2:
- bun test packages/inkstone: 68 pass, 0 fail in Asia/Shanghai, UTC,
  America/Los_Angeles and Pacific/Kiritimati.
- bun scripts/check.mjs inkstone and bun scripts/check.mjs: ok.
- bun test (repo), on 36412a15 merged with origin/main e7cb9dc5:
  6743 pass, 20 skip, 0 fail. main has since moved by cline 0.1.14 and
  zcode 0.1.55 only, and none of the adapter copies changed.
- Broken by hand, each red: no protectName protection; prune_keys default
  off; no post-sign-in prune; no SIGTERM on close; the -15109 retry keeping
  its name.

Not tried: a real InkStone account sign-in on macOS, Linux or Windows (no
account here); a live chat request; magpie end to end with the plugin.
2026-11-07 15:07:06 +08:00
..

SAP AI Core plugin for Magpie

Connect your coding agent through Magpie to existing SAP AI Core deployments. The plugin handles SAP sign-in and token renewal without giving SAP credentials to your agent.

Supported models

GPT discovery accepts model names with major version 6 or higher, including minor versions and variants (for example, gpt-6-mini, gpt-6.2, or gpt-7-mini). No fixed model-name or backend-version allowlist is required. Deployments must still be RUNNING under foundation-models / azure-openai, with matching configuration, active backend, and non-deprecated/non-retired catalog version evidence. When several eligible deployments share a GPT model name, the lowest deployment ID wins, even across backend versions; metadata comes from that selected version. Claude discovery is contract-based, not a fixed name list: any running foundation-models / aws-bedrock Claude deployment that satisfies SAP's documented Bedrock Messages contract is exposed under a conventional ID derived from its model metadata, so a newer compatible model/version needs no plugin release. The live-verified Claude baselines are claude-opus-4-8 and claude-sonnet-4-6. Additional GPT models pass the version-floor policy; additional Claude models are supported by contract. Their live inference, optional capabilities, and limits remain unverified until exercised against a real deployment. SAP's Responses API documentation notes that not all models support Responses; discovery eligibility alone does not prove compatibility.

All support text replies, streaming, and agent-executed function tools; Claude also supports native signed thinking. GPT routes through OpenAI Responses, Claude through native Anthropic Messages on SAP's Bedrock invoke endpoints — both under the same sap-aicore provider and account.

A GPT-5.x or lower-major deployment you already run stays in SAP AI Core but is not discovered or selectable through this plugin; the plugin never upgrades, migrates, or deletes it. Newer eligible GPT (major version 6 or higher) and compatible Claude deployments appear automatically, with no plugin release.

This adapter accepts text, agent-executed tool calls, and image input. Image input is gated per model on the API: a deployment's catalog version must advertise image in its inputTypes. When it does, GPT accepts input_image parts (Responses) and Claude accepts base64 image blocks (Messages); a text-only version rejects images with an explicit unsupported-content error rather than silently dropping them. All current GPT-6 and Claude deployments tested advertise image.

Before you start

You need:

  • Magpie installed, with Bun available for its plugin host.
  • SAP AI Core on the extended service plan and a client-secret service key.
  • An existing RUNNING supported deployment in your selected resource group, under foundation-models / azure-openai (GPT) or foundation-models / aws-bedrock (Claude).

Installation does not create service keys, resource groups, or deployments. See SAP's service plans and deployment guide.

Quick start

1. Create your credential file

Save a JSON file outside this repository, for example ~/aicore-credentials.json:

{
  "authUrl": "https://your-tenant.authentication.eu10.hana.ondemand.com",
  "baseUrl": "https://api.ai.prod.eu10.hana.ondemand.com",
  "clientId": "sb-your-client-id",
  "clientSecret": "your-client-secret",
  "resourceGroup": "your-resource-group"
}

Use your service key's values, not the example URLs. authUrl excludes /oauth/token; baseUrl excludes /v2. Choose the resource group containing your supported deployments. Credential field mapping explains where to find each value.

Protect the file:

chmod 600 ~/aicore-credentials.json

2. Install and sign in

magpie plugin add /absolute/path/to/magpie_aicore
magpie plugin login sap-aicore

When prompted, enter the absolute path to your credential file. Sign-in checks the credentials with SAP before saving the account.

For a released community version, install @magpie-community/opencode-sap-aicore-auth instead of the local folder. New packages are available through the community repository's dist channel after merge, even before their first npm publication (requires Magpie 0.1.1243 or newer).

This package uses the OpenCode plugin shape, but its credential-file sign-in and account-scoped mixed-protocol catalog are verified in Magpie only. Standalone OpenCode compatibility is not claimed.

3. Start the gateway

magpie serve

Use with your coding agent

Configure your agent to use the gateway address and caller authentication configured in Magpie. Select a discovered sap-aicore/<model-id>, such as one of the baselines above.

Pick the protocol that matches the model: GPT models speak OpenAI Responses (call the gateway directly, or use Magpie's Chat Completions conversion), and Claude models speak native Anthropic Messages. The plugin implements no cross-protocol converter — route a Claude model to a Messages client and a GPT model to a Responses client. See the API reference for curl examples and tool-history requirements per protocol.

Credentials and accounts

Magpie remembers the credential-file reference; SAP tokens stay in memory and renew automatically. Keep the file available at the same path.

For multiple credential files or resource groups, sign in each absolute path separately. After rotating credentials, sign in again; restart any other running gateways that need the updated credentials. See accounts and credential updates.

Multiple accounts and routing

Sign in each credential file as a separate account. Magpie then routes and fails over across them automatically.

magpie plugin login sap-aicore   # enter ~/aicore-a.json
magpie plugin login sap-aicore   # enter ~/aicore-b.json
magpie accounts sap-aicore       # confirm both are listed

Choosing a routing mode

The plugin does not report SAP quota windows to Magpie, so quota-aware modes (smart, pace) have no SAP data to weigh and behave like order. Use one of the two recommended modes:

Situation Recommended setup Command
One primary account, others as backup routing=order + stays=session magpie provider set sap-aicore routing=order
Several concurrent coding sessions routing=usage + stays=session magpie provider set sap-aicore routing=usage

stays=session keeps each conversation on the account that answered its first turn, so tool loops and follow-up turns stay together and do not jump accounts mid-session. New sessions are spread across accounts by recent load.

Enable sink so a rate-limited account moves to the back immediately instead of being retried:

magpie provider set sap-aicore sink=on

What multiple accounts protect against

Setup Benefit Limit
Different credential files, same resource group Separate credential identities; one credential failure leaves others working Same SAP deployments and quota
Different resource groups, same tenant Separate deployments and workloads Tenant-level model rate limits are shared by default
Different tenants Quota and credential isolation Shared hyperscaler capacity or regional outages can still affect both

SAP rate limits are tenant-wide and reset per minute. A 429 response can mean the tenant quota is exhausted, a resource-group limit is hit, or the backend is temporarily saturated — account rotation does not help when the limit is tenant-wide. See SAP's rate limit documentation for quota management and increase requests.

Troubleshooting

Symptom What to check
Sign-in fails Absolute file path, JSON fields, service-key values, and service URLs.
No models appear Resource group, deployment status, model eligibility, and matching active-version evidence.
A selected model is unavailable Deployment status or version may have changed; refresh discovery or restart the gateway.
Unsupported parameter Check the supported request fields.

See troubleshooting for account selection, errors, and gateway constraints.

Live run record

Authorized, credential-redacted live verification on 2026-11-03 (plugin 0.2.3, Node v26.13.0), dispatched through the plugin's own auth.loader().fetch to real SAP AI Core in an existing resource group with isolated temporary stores. This exercises the plugin-to-SAP dispatch path, not the installed Magpie gateway process; the gateway journey is recorded separately in the source project. No tokens, client secrets, resource-group names, or deployment URLs are shown; eight synthetic generations were used.

Scenario gpt-6-astra (Responses) claude-opus-4-8 (Messages)
Plain text HTTP 200, completed, usage 14→8 HTTP 200, end_turn, usage 29→17
Streamed HTTP 200, incremental output_text deltas, response.completed HTTP 200, incremental deltas, stop_reason: end_turn, message_stop
Forced tool call function_call verify_value {"value":7} tool_use verify_value {"value":7}
Tool-result continuation HTTP 200, completed, "The result is 14." HTTP 200, end_turn, "…returned 14 (7 doubled)."

Each request carried the account's SAP Bearer and resource-group header injected by the loader; the caller's gateway key was never forwarded. This single dated run is not a quota, latency, or billing guarantee, and does not cover token expiry/renewal, 429/quota exhaustion, reauthorization races, or reasoning-signature replay.

Limitations and security

  • Only running deployments are exposed. GPT requires major version 6 or higher, not a fixed model/version list; Claude is accepted by the documented SAP Bedrock Messages contract (foundation-models / aws-bedrock). Existing GPT-5.x and lower-major deployments remain in SAP but are never listed, upgraded, or deleted.
  • Text, agent-executed function tools, and image input (Claude also: native signed thinking and cache_control). Image input is enabled per model from the catalog inputTypes and rejected with an explicit error on text-only versions; audio, video, hosted tools, and other multimodal input remain unsupported.
  • No deployment management, server-side conversation storage, or automatic model substitution.
  • Capability status differs by evidence: the GPT pair and the two Claude baselines are directly verified; other eligible models' live inference, optional reasoning controls, and context/output limits are not verified until exercised against a real deployment. Being listed never asserts completed live acceptance.
  • Keep credentials outside the repository. Never use a SAP client secret or access token as the agent's gateway key.
  • Local cancellation does not guarantee SAP computation or billing stops. Magpie may retry failed requests; do not assume exactly-once generation.
  • MIT licensed; not affiliated with or endorsed by SAP. The license does not grant SAP productive-use approval.

More information