Skip to content

feat(ai-gateway): support AWS Bedrock SigV4 auth for custom LLMs#3097

Open
kilo-code-bot[bot] wants to merge 3 commits intomainfrom
custom-llm-aws-bedrock-signing
Open

feat(ai-gateway): support AWS Bedrock SigV4 auth for custom LLMs#3097
kilo-code-bot[bot] wants to merge 3 commits intomainfrom
custom-llm-aws-bedrock-signing

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot Bot commented May 7, 2026

Summary

  • Add an optional aws_bedrock block (access_key_id, secret_access_key, region) to CustomLlmDefinitionSchema. When present, the custom LLM provider uses AWS SigV4 signing against the bedrock service instead of an Authorization: Bearer header.
  • Introduce an optional signRequest hook on Provider; upstream-request.ts invokes it to compute auth headers (and optionally rewrite the target URL) before fetch. Non-Bedrock providers keep the existing Bearer flow unchanged.
  • New bedrock-signer.ts rewrites the URL to https://bedrock-runtime.<region>.amazonaws.com/model/<internal_id>/invoke (or invoke-with-response-stream when body.stream === true) and signs with @aws-sdk/signature-v4 + @aws-crypto/sha256-js.

Admins configure a Bedrock-backed custom LLM via the existing JSON editor, e.g.:

{
  "internal_id": "anthropic.claude-sonnet-4-20250514-v1:0",
  "base_url": "https://bedrock-runtime.us-east-1.amazonaws.com",
  "api_key": "",
  "aws_bedrock": {
    "access_key_id": "...",
    "secret_access_key": "...",
    "region": "us-east-1"
  },
  "remove_from_body": ["model"],
  "extra_body": { "anthropic_version": "bedrock-2023-05-31" },
  "openclaw_settings": { "api_adapter": "anthropic-messages" }
}

Verification

Manually inspected the diff; the Bedrock path is only exercised when aws_bedrock is set on a custom LLM definition, otherwise upstream-request.ts falls through to the existing Bearer auth. Did not run pnpm typecheck/pnpm test/pnpm format locally before pushing per user instruction — please verify in CI.

Visual Changes

N/A — no UI changes; the admin JSON editor already accepts the new aws_bedrock field.

Reviewer Notes

  • @aws-sdk/signature-v4 and @aws-crypto/sha256-js added to apps/web/package.json; pnpm install required.
  • Credentials are stored plaintext in custom_llm2.definition jsonb, matching the existing api_key storage model for custom LLMs (admin-only, kilo-internal/*). If we want envelope-encrypted storage like byok_api_keys, that's a separate follow-up.
  • parseStreamFlag in bedrock-signer.ts reads stream from the already-serialized body; admins should NOT include "stream" in remove_from_body, otherwise streaming requests will be routed to the non-streaming endpoint.

Add an optional aws_bedrock block to CustomLlmDefinitionSchema with
access_key_id, secret_access_key and region. When present, upstream
requests are SigV4-signed against the bedrock service (and the URL
is rewritten to /model/<internal_id>/invoke[-with-response-stream])
instead of using Authorization: Bearer.

This is wired through a new optional signRequest hook on Provider
that runs in upstream-request.ts; Bearer auth is still the default
for all other providers.
Comment thread apps/web/package.json
@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot Bot commented May 7, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • apps/web/src/lib/ai-gateway/providers/get-provider.ts
  • apps/web/src/lib/ai-gateway/providers/upstream-request.ts

Reviewed by gpt-5.5-2026-04-23 · 387,699 tokens

Comment thread apps/web/src/lib/ai-gateway/providers/upstream-request.ts
Addresses review: non-Bedrock custom LLMs with omitted api_key no longer
send 'Authorization: Bearer undefined'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant