Skip to content

Migrate LLM stack to Anthropic Claude via Claude Platform on AWS - #162

Merged
neuromechanist merged 20 commits into
developfrom
feature/claude-platform-aws
Aug 19, 2026
Merged

Migrate LLM stack to Anthropic Claude via Claude Platform on AWS#162
neuromechanist merged 20 commits into
developfrom
feature/claude-platform-aws

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

Moves all LLM calls from OpenRouter to Anthropic Claude served through the Claude Platform on AWS (Anthropic-operated Messages API, AWS Marketplace billing; not Amazon Bedrock), mirroring the nemar-cli migration.

Model policy

  • Offered models: claude-haiku-4-5 (default) and claude-sonnet-5 (web UI dropdown option). Opus is not offered.
  • The evaluation judge and the vision agent stay on Haiku 4.5 regardless of the annotation model (Claude models are natively multimodal, replacing the separate Qwen vision model).
  • Legacy OpenRouter-style ids (anthropic/claude-haiku-4.5) are accepted as aliases; non-Anthropic models are rejected with HTTP 400.

Backend

  • New src/utils/anthropic_llm.py factory on langchain-anthropic (official SDK underneath). Server mode reads ANTHROPIC_API_KEY + ANTHROPIC_BASE_URL + ANTHROPIC_WORKSPACE_ID (the endpoint rejects requests without the workspace header). Prompt caching via cache_control on system messages is preserved.
  • Sonnet 5 rejects temperature; the factory gates sampling params by model, and maps disable_reasoning to thinking: disabled only where thinking is on by default.
  • BYOK now takes first-party Anthropic keys (sk-ant-) via X-Anthropic-Key (legacy X-OpenRouter-Key still accepted as transport) and routes to api.anthropic.com without the workspace header.
  • Provider routing, per-user cache lanes, the OpenRouter/LiteLLM modules, and the Ollama path are removed. Missing server credentials map to 503; invalid models to 400.

CLI, frontend, worker, ops

  • CLI defaults to the new model ids; --provider options removed; credentials store anthropic_api_key (HEDIT_ANTHROPIC_API_KEY env override); standalone mode can run on the server env credentials.
  • Frontend dropdown: Claude Haiku 4.5 (default) and Claude Sonnet 5; provider plumbing removed.
  • Worker forwards X-Anthropic-Key; docker compose, CI workflows, dev scripts, and deployment docs updated (new docs/deployment/claude-platform-aws.md).

Testing

  • Live smoke tests against the AWS endpoint passed for both models with the project key, including prompt caching headers.
  • 440 non-integration tests pass. 7 live integration tests pass (annotation agent, judge, full workflow, API endpoints via lifespan); vision path verified with a real image through VisionAgent.
  • tests/test_integration_anthropic.py replaces the OpenRouter integration tests, gated on ANTHROPIC_API_KEY.

Required repository configuration (manual)

  • Set secret ANTHROPIC_API_KEY and repository variables ANTHROPIC_BASE_URL, ANTHROPIC_WORKSPACE_ID for CI
  • Delete the OPENROUTER_API_KEY_FOR_TESTING secret and repository variable (the variable exposes a key in plaintext) and revoke the OpenRouter keys

Server mode reads ANTHROPIC_API_KEY/ANTHROPIC_BASE_URL/ANTHROPIC_WORKSPACE_ID
(workspace header required by the AWS endpoint); BYOK keys go to the
first-party API. Offered models: claude-haiku-4-5 (default) and
claude-sonnet-5. Replaces langchain-openai/litellm deps with
langchain-anthropic. Verified live against both models.
- create_anthropic_workflow/create_byok_workflow/create_vision_agent replace
  the OpenRouter factories; provider routing and user-id cache lanes removed
- BYOK accepts Anthropic keys (sk-ant-) via X-Anthropic-Key; legacy
  X-OpenRouter-Key header still accepted as transport
- Unknown models rejected with 400; server mode no longer needs a per-request
  key (credentials come from the environment)
- Ollama path removed; evaluation judge defaults to Claude Haiku 4.5
- Feedback triage and telemetry defaults updated
- Defaults: claude-haiku-4-5 for annotation, evaluation, and vision;
  claude-sonnet-5 offered via --model
- Provider options removed (single provider now); credentials store
  anthropic_api_key with HEDIT_ANTHROPIC_API_KEY env override
- Standalone mode can run on ANTHROPIC_API_KEY env credentials without a
  stored BYOK key; client sends X-Anthropic-Key
…thropic-Key

Provider plumbing removed from the web UI (single provider now); model
values use first-party ids. Worker BYOK detection and header forwarding
accept the new X-Anthropic-Key header alongside the legacy one.
- New test_anthropic_llm.py unit tests (normalization, server/BYOK modes,
  temperature and thinking gating, caching wrapper)
- test_integration_openrouter.py renamed to test_integration_anthropic.py,
  gated on ANTHROPIC_API_KEY
- Security, CLI, and endpoint tests updated for X-Anthropic-Key and
  first-party model ids; removed tests of deleted OpenRouter modules
- 440 non-integration tests pass (LSP tests fail locally for an unrelated
  hed-lsp version issue)
CI now uses the ANTHROPIC_API_KEY secret plus ANTHROPIC_BASE_URL and
ANTHROPIC_WORKSPACE_ID repository variables (must be configured on GitHub).
Factory raises RuntimeError when ANTHROPIC_API_KEY is unset in server mode;
endpoints map it to 503 while model validation errors stay 400.
- New docs/deployment/claude-platform-aws.md replaces openrouter.md
- Ollama/GPU setup removed from deployment guides; Anthropic credential
  setup and model selection (claude-haiku-4-5 default, claude-sonnet-5
  optional) documented throughout
- BYOK manual tests rewritten for X-Anthropic-Key with sk-ant keys
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

- 400 mapping for rejected models on all four annotate endpoints; exact
  503 with missing server credentials; alias acceptance over HTTP
- BYOK key extraction via both X-Anthropic-Key and legacy header
- Standalone-mode credential gate (env credentials, no credentials,
  API mode still requires key)
- Replace stale pre-migration telemetry test data; pin the BYOK
  format-rejection test to 401
Critical:
- BYOK LLMs now pin base_url to api.anthropic.com explicitly; ChatAnthropic
  otherwise inherits the server's ANTHROPIC_BASE_URL from the process env,
  routing BYOK keys to the AWS endpoint that rejects them (verified live)
- Anthropic exceptions map to specific HTTP statuses via a shared
  classifier across all four annotate endpoints (401 auth, 403 permission,
  413 context overflow, 400 bad request, 502 connection, 504/429 kept)

Robustness:
- Startup validates credentials with a free count_tokens call; failure
  keeps the server up but marks /health degraded instead of booting a
  healthy-looking server that 500s on every request
- Vision-agent init failure no longer takes down text annotation (503 on
  image endpoints only)
- CachingLLMWrapper raises TypeError on unsupported message types instead
  of silently relabeling them as user turns
- CLI warns once when a legacy OpenRouter key is found in credentials;
  client gains explicit 400/429 error branches
- Frontend streaming handlers surface the backend's error detail instead
  of a bare HTTP status

Cleanup: dead LLM_PROVIDER_PREFERENCE read removed, user_id docstrings no
longer claim telemetry recording, obsolete OpenRouter benchmark examples
deleted, worker forwards X-OpenRouter-Vision-Model, stale docstrings and
comments corrected. All 454 unit tests pass; lifespan integration tests
pass against the live endpoint.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploying hedit with  Cloudflare Pages  Cloudflare Pages

Latest commit: a12b5df
Status: ✅  Deploy successful!
Preview URL: https://4af71b7e.hedit.pages.dev
Branch Preview URL: https://feature-claude-platform-aws.hedit.pages.dev

View logs

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