← Catalog

@jack-yang/magpie-portkey-bedrock

Portkey AWS Bedrock provider for Magpie and pi, with tools, vision, reasoning and prompt caching. Built on @ai-sdk/amazon-bedrock.

Provider

Install

Install with PiG

pig install npm:@jack-yang/magpie-portkey-bedrock

Install with Pi

pi install npm:@jack-yang/magpie-portkey-bedrock
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 2.6.2 (README.md). PiG does not review it.

magpie-portkey-bedrock

A magpie provider for AWS Bedrock models through Portkey. It runs the real @ai-sdk/amazon-bedrock transport (native Bedrock Converse protocol) and works in both magpie (via magpie's pi package bridge) and pi.

The provider id is portkey-bedrock. Its models are available to every agent connected to magpie.

中文文档:README.zh-CN.md

[!IMPORTANT] Upgrading from 1.2.x or earlier: sign in your accounts again. Each account now carries its own gateway, route and name from the sign-in form; config files no longer route anything.

  1. Sign out every existing Portkey Bedrock account (Providers → Portkey Bedrock). Accounts from earlier versions hold only a key and no gateway, so their requests fail with Provider is not configured. Nothing is sent with them, so their keys never leave your machine.
  2. Sign in again through the form: base URL, provider slug, API key and an optional name.
  3. Delete config.local.json beside index.ts if all it holds is baseUrl and provider. They are ignored now; only configId and extra headers still apply (see Configure your gateway).

Features

  • Native Bedrock Converse streaming through @ai-sdk/amazon-bedrock.
  • GUI sign-in form: base URL, Portkey provider slug, API key and an optional account name — no config editing, no browser. Every account routes through its own gateway.
  • Multi-account: each signed-in account carries its own key, gateway URL and provider route; magpie rotates, fails over and rate-limits them per account.
  • Dynamic model discovery: once an account is signed in, the provider asks that account's gateway for its model list (GET /v1/models) and merges what it actually serves into the catalog; failures keep the catalog.
  • Text, vision, streamed tool arguments and tool results, including image results and failed tools. Tool arguments parse incrementally — linear in stream length, not quadratic.
  • Reasoning levels, including xhigh and max where declared; signed and redacted reasoning survives replay. Thinking streams with display: summarized, so the first token arrives while the model reasons instead of after the whole reasoning pass.
  • Prompt-cache checkpoints gated by model family (Claude and Nova only — other Bedrock families ignore or reject cachePoint) with cacheRetention support, including Bedrock's one-hour TTL (long).
  • Input, output, cache-read and cache-write token accounting with catalog prices.
  • Cancellation, request timeouts, payload inspection and response hooks.
  • HTTP status and retry headers forwarded to magpie for its routing and failover logic.
  • When Portkey refuses a request, the error says why in its own words and what to change: a budget exhausted, a key without the scope, an AWS principal missing an IAM action, an organization that only accepts saved providers or configs (inline_…_blocked), or one whose guardrail requires request logging (446). It carries Portkey's trace id for the request.
  • A request that fails in a way that may pass (429, 408, 5xx) is sent again on the same account, so the account's prompt cache is read again rather than rewritten on another.

Install in magpie

# npm (after publishing)
magpie plugin add @jack-yang/magpie-portkey-bedrock

# or GitHub
magpie plugin add github:yangwudong/magpie-portkey-bedrock

# or a local checkout
git clone https://github.com/yangwudong/magpie-portkey-bedrock.git
magpie plugin add "$PWD/magpie-portkey-bedrock"

Then sign in with your Portkey gateway account (the Providers page, or magpie plugin login portkey-bedrock). The sign-in form asks its fields one after another and saves the account after the last — no browser, nothing else to confirm:

  1. Base URL — your Portkey gateway's Bedrock-compatible base URL. Requests go to /model/{encoded model id}/converse-stream.
  2. Provider slug — the x-portkey-provider route for this account: your Bedrock provider's slug in Portkey's Model Catalog, written @your-bedrock-provider. Required.
  3. API key — the account's Portkey gateway key.
  4. Account name (optional) — what magpie lists the account as. Left empty, it is named by both ends of its key, like API key AbCd…Yz12; the rest of the key is never shown.

Names identify accounts: signing in again under a name an account already has updates that account (new key, gateway or route) instead of adding another. Give each account its own name.

An empty base URL means Portkey's public gateway, https://api.portkey.ai/v1. The slug has no default: it names a provider in your own Model Catalog. The hints never show your own configuration. magpie keeps each sign-in in plugin-auth.json under its configuration directory. Sign in again for each further account: every account keeps its own key, gateway and provider route, and magpie's routing, failover and account limits apply per account. Requests send the selected account's key as both Authorization: Bearer … and x-portkey-api-key.

Select Providers → Portkey Bedrock, then choose a portkey-bedrock/… model for your agent:

magpie claude portkey-bedrock/us.anthropic.claude-opus-5-5

magpie installs Bun, the plugin's runtime dependencies and its pi runtime when needed. To reload edits in the app, turn the plugin off and on in Plugins.

Configure your gateway

There is nothing to configure: every account's gateway and route come from its sign-in, and the package ships no config file.

The switches

Three settings apply to every account, each set in two places: a value set in magpie's Options wins over the config file, which wins over the default. log and cacheTtl1h are off by default; retry is 2. Why each is what it is, with the Portkey behaviour behind it, is in docs/portkey-reference.md.

In magpie: Plugins → the Portkey Bedrock row → Options. A JSON box opens with the three switches; edit and save, and magpie restarts the plugin. There is nothing to open and no path to find.

In the config file, for plain pi or by hand: ~/.config/magpie/portkey-bedrock/config.json. It lives outside the installed plugin, so updates leave it alone. A config.local.json beside index.ts from earlier versions is still read while the new file does not exist; move it over, since plugin updates may remove it:

{
  "configId": "pc-your-config",
  "log": false,
  "retry": 2,
  "cacheTtl1h": false,
  "headers": { "x-portkey-trace-id": "magpie" }
}
  • log: whether Portkey may store the content of requests and responses in its logs. Off by default. Off, every request carries x-portkey-debug: false (Portkey's "DO NOT TRACK"): the gateway keeps tokens, cost and latency, but neither your prompts nor the responses. On, Portkey stores full request and response content. A x-portkey-debug header of your own in headers takes precedence over the switch.

    [!NOTE] Portkey documents this header for its /v1/chat/completions route, and this provider sends it the same way on /model/{id}/converse-stream. Whether the managed gateway honours it there is not documented: check a request in Portkey's Logs page after enabling the provider, and turn log on only if you are fine with full content being stored. The switch never removes usage records (tokens, cost, latency), only the request and response content.

  • retry: how many more times this provider sends a request again on the same account when Bedrock answers 429, 408 or a 5xx, from 0 to 5. 2 by default. Staying on the account keeps its prompt cache; when magpie fails over to another account instead, that account starts with no cache and pays to write it again. It costs up to 3 seconds of waiting on a request that keeps failing (1s, then 2s), and less when Bedrock says how long to wait: its Retry-After is followed, and a wait of a minute or more is not waited at all, so magpie hears at once and can move on. When every try fails, magpie gets the last reply and its Retry-After, as before. Anything else (400, 403, 412) goes straight back. Set 0 to hand every failure to magpie at once. The retries are this provider's own, not Portkey's gateway's: asking the gateway would put an inline config on every request, which an organization blocking inline configs refuses and which would replace a default config set on your API key.

  • cacheTtl1h: keep Claude prompt-cache checkpoints for one hour instead of Bedrock's five-minute default, so a conversation you come back to still reads its cache. Off by default; Claude only (Nova caches on its own, for five minutes). Portkey documents the one-hour TTL for Claude Opus 4.5, Sonnet 4.5 and Haiku 4.5; whether your Bedrock models accept it is for you to confirm, as the catalog also lists later ones Portkey's table does not. A caller's own cacheRetention still stands: none sends no checkpoint and long asks for the hour whatever the switch says.

The rest of the file:

  • configId: an x-portkey-config configuration id sent with every account's requests.
  • headers: additional non-secret gateway headers sent with every account's requests.
  • models: extra models that the gateway's /models list hides but that can be called by id (e.g. ["us.anthropic.claude-fable-5-2"]). Same entry format as models.json; they are always registered, and an entry overrides a catalog model with the same id.

A switch misspelt in magpie's Options (logs for log) is refused rather than ignored, and the reason goes to magpie's log; otherwise a switch you believe off would stay as it was. A name that is not a switch is fine in the config file, which holds more than switches.

baseUrl and provider from earlier versions' files are ignored — they route nothing now. Credentials belong in magpie's sign-in, never in this file: the reader rejects API keys and secret headers (apiKey, virtualKey, authorization, *-api-key, token, secret, cookie). Restart the plugin after changing it.

Each model entry is checked when the plugin starts: an unknown field (e.g. contextwindow) or a wrong type is reported with the entry it is in. A file that cannot be read this way is set aside, not fatal: the provider still loads with the built-in catalog, and the reason goes to magpie's log.

Requests are sent uncompressed. Portkey's deployed gateway reads the body as plain JSON and does not decompress: a gzip or deflate body answers 400 with Value null at 'messages' even at 95 bytes, on both /model/{id}/converse-stream and /v1/messages. Compressing the request needs the gateway to enable request decompression first. Responses are also sent uncompressed, and Accept-Encoding: gzip, br changes nothing.

Models

models.json is an editable catalog. Entries may be model ID strings or objects with id, name, reasoning, thinkingLevelMap, input, contextWindow, maxTokens and cost. Prices are USD per million tokens, with separate input, output, cacheRead and cacheWrite values. Fields an entry leaves out take per-family defaults: Anthropic and Nova Pro / Premier ids get reasoning, image input, a 1M context and 64K output; other families get text only, no reasoning, 200K context and 8K output. Prices default to 0.

The included catalog covers the current Bedrock line-up plus common Amazon / DeepSeek / Meta / Mistral models. Availability, limits and prices depend on your AWS account and Portkey route; update the catalog to match them. When an account is signed in, magpie refreshes the list through the provider's refreshModels: the gateway's /models response is merged with the catalog — catalog entries keep their metadata, unknown ids are added with conservative defaults. The catalog's name is what magpie's model picker displays (e.g. Claude Opus 5.5 instead of the raw Bedrock id); the id remains what requests use.

When the gateway will not list its models, the catalog stays and the reason goes to magpie's log rather than failing the refresh:

  • Portkey's own refusal (for example 403 with Error Code: 033): the API key may not have the scope to list models (completions.write), or the provider slug may belong to another workspace.
  • An AWS refusal naming an IAM action (for example bedrock:ListFoundationModels): the AWS principal behind the route is not allowed that action. Chat is unaffected; either allow the action in AWS or list the models by hand in config.json (see models above).

Any other failure (a 5xx, a body that is no error the gateway owns) is reported with its status and what the gateway said, and nothing more: there is nothing in it you could act on.

Who can see your requests in Portkey

With log off, Portkey stores no request or response content, so neither you nor your organization's admins can read it in the Logs page: admins' log permissions govern what was stored, and nothing was. What is kept is the metadata: when, which model, which key, how long. That is Portkey's own logs. Two things are outside them, and outside anything this provider can switch: an Enterprise or self-hosted gateway can export full prompts and replies to an OpenTelemetry endpoint of its operator's choosing, switched on in the gateway's environment, with no request header to turn it off and nothing in the documentation saying log keeps content out of it; and a guardrail that checks content reads the request either way. If your gateway is not api.portkey.ai but your organization's own, its operator decides what is exported, and is who to ask. An organization can also forbid turning logging off; its requests are then refused with a 446, and the error says to turn log on. The details and their sources are in docs/portkey-reference.md.

NameModel idContextMax output
Claude Haiku 4.5us.anthropic.claude-haiku-4-5-20251001-v1:0200,00064,000
Claude Opus 4.8us.anthropic.claude-opus-4-81,000,00064,000
Claude Opus 5us.anthropic.claude-opus-51,000,00064,000
Claude Opus 5.5us.anthropic.claude-opus-5-51,000,000128,000
Claude Sonnet 5us.anthropic.claude-sonnet-51,000,00064,000
Claude Sonnet 5.5us.anthropic.claude-sonnet-5-51,000,000128,000
Claude Sonnet 4.5anthropic.claude-sonnet-4-5-20250929-v1:0200,00064,000
Claude 3.5 Haikuanthropic.claude-3-5-haiku-20241022-v1:0200,0008,192
Nova Premieramazon.nova-premier-v1:01,000,00032,000
Nova Proamazon.nova-pro-v1:0300,0006,400
Nova Liteamazon.nova-lite-v1:0300,0006,400
Nova Microamazon.nova-micro-v1:0128,0004,096
DeepSeek R1deepseek.r1-v1:0128,0008,192
Llama 3.3 70Bmeta.llama3-3-70b-instruct-v1:0128,0008,192
Pixtral Largemistral.pixtral-large-2502-v1:0128,0008,192

Use in pi

From a local checkout:

pi -e ./index.ts

Use /login for portkey-bedrock: pi asks the same four fields. Enable only one copy of this provider per session.

OpenCode plugin vs pi extension

This package is a pi extension: the real @ai-sdk/amazon-bedrock SDK runs here and speaks native Bedrock Converse, which is what enables the prompt-cache checkpoints, reasoning-effort mapping and signed-thinking replay above. A lighter alternative is an OpenCode provider plugin (magpie's gateway converts to chat completions and a tiny fetch adds the gateway headers) — simpler, but generic chat-completions traffic cannot carry Bedrock-specific features like explicit cache points. The two approaches use different provider ids and can be installed side by side.

Development and verification

Tested with pi 1.5.2 and magpie's Bun plugin host.

bun install --ignore-scripts
bun run check   # typecheck + tests

Tests use real AWS event-stream frames against the Bedrock SDK to verify authentication, conversion, tools, images, reasoning, cache markers, usage, Unicode chunk boundaries, aborts and failures. No live credentials are used.

For integration coverage:

git clone --depth 1 https://github.com/yetone/magpie.git /tmp/magpie
MAGPIE_SOURCE_DIR=/tmp/magpie bun test test/magpie.test.ts

This starts magpie's actual internal/plugin/host.js under Bun in a temporary configuration directory and sends Anthropic requests through the pi bridge. Without MAGPIE_SOURCE_DIR, that integration test is skipped. Live Portkey access is not part of the automated tests.

npm publish creates an installable archive containing the provider, catalog and documentation. Dependencies, tests and local overrides are excluded.

Marketplace

Tag the repository magpie-plugin for automatic discovery under Plugins → Discover → Unofficial, on GitHub. For the curated list, PR an entry into magpie-community/plugins' registry.json after publishing to npm:

{
  "package": "@jack-yang/magpie-portkey-bedrock",
  "name": "Portkey Bedrock",
  "providers": ["portkey-bedrock"],
  "summary": {
    "en": "AWS Bedrock through Portkey, with tools, vision, reasoning, prompt caching and dynamic model discovery.",
    "zh": "通过 Portkey 使用 AWS Bedrock,支持工具调用、图像、推理、提示词缓存与动态模型发现。"
  }
}

Credits

Configuration layering, secret hygiene and the streaming core are based on TianZuo555/magpie-portkey (MIT). This package uses a different provider id (portkey-bedrock), so the two can be installed side by side.

License

MIT