Skip to content

fix(bookstack-agent): use Authorization: Bearer when routing via LLM gateway#97

Merged
amrit110 merged 2 commits into
mainfrom
fix/bookstack-agent-gateway-auth
Jun 16, 2026
Merged

fix(bookstack-agent): use Authorization: Bearer when routing via LLM gateway#97
amrit110 merged 2 commits into
mainfrom
fix/bookstack-agent-gateway-auth

Conversation

@amrit110

Copy link
Copy Markdown
Member

Problem

The Anthropic SDK sends x-api-key: <key> for authentication. The proxy gateway requires Authorization: Bearer <token>. When LLM_BASE_URL is set, every request failed with 401 invalid x-api-key — either because the gateway rejected the missing Bearer header, or because the gateway key was sent directly to Anthropic.

Fix

  • BookstackQAAgent: adds a llm_api_key parameter (read from LLM_API_KEY env var). When LLM_BASE_URL is set, the SDK is initialised with default_headers={"Authorization": "Bearer <key>"} so the gateway authenticates it correctly. The gateway's build_upstream_headers then replaces the auth header with the real provider key before forwarding to Anthropic.
  • api/main.py: startup validation now checks for LLM_API_KEY (instead of ANTHROPIC_API_KEY) when LLM_BASE_URL is configured.

Deployment change required

When using the gateway, set both env vars on the bookstack API container:

LLM_BASE_URL=https://proxy.vectorinstitute.ai
LLM_API_KEY=<gateway-issued bearer token>

ANTHROPIC_API_KEY is no longer needed when LLM_BASE_URL is set.

Test plan

  • Deploy with LLM_BASE_URL + LLM_API_KEY set — agent should connect successfully
  • Deploy without LLM_BASE_URL (ANTHROPIC_API_KEY only) — agent should still work via direct Anthropic
  • Deploy with LLM_BASE_URL but without LLM_API_KEY — startup should fail with a clear error message

amrit110 and others added 2 commits June 16, 2026 08:30
…gateway

The Anthropic SDK sends x-api-key for auth, but the proxy gateway requires
Authorization: Bearer. When LLM_BASE_URL is set, the agent now reads
LLM_API_KEY (the gateway-issued bearer token) and injects it via
default_headers so the gateway accepts the request.

Previously the SDK sent x-api-key: <gateway_token> directly to Anthropic
(if LLM_BASE_URL was unset) or to the gateway (where it failed auth), both
resulting in a 401 'invalid x-api-key'.

Startup validation is also updated: when LLM_BASE_URL is set, LLM_API_KEY
is required instead of ANTHROPIC_API_KEY.
@amrit110 amrit110 merged commit e3e4a12 into main Jun 16, 2026
9 checks passed
@amrit110 amrit110 deleted the fix/bookstack-agent-gateway-auth branch June 16, 2026 12:33
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