Skip to content

chore(tests): source live Bedrock Anthropic model from env var - #26722

Closed
ryan-crabbe-berri wants to merge 2 commits into
litellm_internal_stagingfrom
litellm_chore-env-driven-bedrock-test-models
Closed

chore(tests): source live Bedrock Anthropic model from env var#26722
ryan-crabbe-berri wants to merge 2 commits into
litellm_internal_stagingfrom
litellm_chore-env-driven-bedrock-test-models

Conversation

@ryan-crabbe-berri

@ryan-crabbe-berri ryan-crabbe-berri commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Centralize the Bedrock Anthropic model IDs used by live tests behind 3 env vars (one per route prefix). Each env var holds a full, copy-pasteable model path. EOL bumps become CircleCI UI changes, no PR.
  • Motivation: PR fix(tests): replace deprecated Bedrock Claude 3.7 Sonnet model ID #26721 had to touch 16 files when AWS EOL'd Claude 3.7 Sonnet on Bedrock, then a follow-up commit had to swap Claude 3.5 Sonnet v2 (also EOL on 2026-03-01) for Sonnet 4.5. AWS is rolling out EOLs continuously; this PR makes that maintenance trivial.
  • Scope: only live tests are migrated:
    • tests/local_testing/test_function_calling.py::test_aaparallel_function_call_with_anthropic_thinking (Bedrock parametrize entry)
    • tests/pass_through_unit_tests/test_anthropic_messages_prompt_caching.py (TestBedrockConversePromptCaching and TestBedrockInvokePromptCaching)
  • Mocked transformation tests (~10 files) intentionally keep their hardcoded model IDs. The string is opaque in those tests — it never reaches AWS, so EOLs don't break them.
  • No fallback default. Test files fail loud at collection time with KeyError if any env var is missing. Avoids the dead-code trap of an unused fallback (see existing precedents BEDROCK_TEST_MODEL, LITELLM_PROXY_RESPONSES_MODEL which silently default forever).

Required before merge

Add the following 3 env vars to https://app.circleci.com/settings/project/github/BerriAI/litellm/environment-variables. Without all 3, CI will fail at collection.

Env var Value
BEDROCK_ANTHROPIC_MODEL bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0
BEDROCK_ANTHROPIC_CONVERSE_MODEL bedrock/converse/us.anthropic.claude-sonnet-4-5-20250929-v1:0
BEDROCK_ANTHROPIC_INVOKE_MODEL bedrock/invoke/us.anthropic.claude-sonnet-4-5-20250929-v1:0

Local dev requires exporting all 3 (or setting via .envrc/.env).

Test plan

  • Verified locally: without env vars → KeyError at collection (loud failure). With all 3 set → parametrize ID and get_model() resolve to the override values.
  • All 3 CircleCI UI env vars set before merge.
  • CI passes.

How to bump after future EOLs

Edit the 3 CircleCI UI values (all visible together alphabetically). No code change, no PR. If you forget one, CI surfaces the EOL 404 from the un-bumped one — self-correcting.

@ryan-crabbe-berri
ryan-crabbe-berri requested a review from a team April 28, 2026 22:57
@greptile-apps

greptile-apps Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR centralizes Bedrock Anthropic model IDs used by live tests behind three env vars (BEDROCK_ANTHROPIC_MODEL, BEDROCK_ANTHROPIC_CONVERSE_MODEL, BEDROCK_ANTHROPIC_INVOKE_MODEL) so future AWS EOL bumps require only a CircleCI UI change rather than a code PR. The two changed files swap hardcoded model strings for os.environ[...] lookups; the scope is intentionally limited to live tests, leaving mocked tests untouched.

Confidence Score: 5/5

Safe to merge once the three CircleCI env vars are configured as described in the PR.

Changes are limited to two test files; no production code is touched. All previously raised concerns (collection-time KeyError, missing CircleCI config block) were acknowledged as intentional by the author. No new P0/P1 issues are present.

No files require special attention beyond verifying that all three CircleCI env vars are set before merging.

Important Files Changed

Filename Overview
tests/local_testing/test_function_calling.py Replaces hardcoded Bedrock model string in @pytest.mark.parametrize with os.environ["BEDROCK_ANTHROPIC_MODEL"]; env-var is evaluated at collection time (intentional loud failure per author).
tests/pass_through_unit_tests/test_anthropic_messages_prompt_caching.py Replaces two hardcoded model strings in get_model() methods with os.environ["BEDROCK_ANTHROPIC_CONVERSE_MODEL"] and os.environ["BEDROCK_ANTHROPIC_INVOKE_MODEL"]; evaluated lazily at test-run time (not collection time), so no collection-error risk here.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CircleCI env vars\nBEDROCK_ANTHROPIC_MODEL\nBEDROCK_ANTHROPIC_CONVERSE_MODEL\nBEDROCK_ANTHROPIC_INVOKE_MODEL] --> B{pytest collection}
    B -->|BEDROCK_ANTHROPIC_MODEL missing| C[KeyError — collection aborts\ntest_function_calling.py]
    B -->|All vars set| D[test_aaparallel_function_call_with_anthropic_thinking\nparametrize resolves model]
    B -->|All vars set| E[TestBedrockConversePromptCaching.get_model\nreturns BEDROCK_ANTHROPIC_CONVERSE_MODEL]
    B -->|All vars set| F[TestBedrockInvokePromptCaching.get_model\nreturns BEDROCK_ANTHROPIC_INVOKE_MODEL]
    D --> G[Live Bedrock API call]
    E --> G
    F --> G
Loading

Reviews (9): Last reviewed commit: "chore(tests): source bedrock anthropic l..." | Re-trigger Greptile

Comment thread tests/local_testing/test_function_calling.py Outdated
Comment thread tests/local_testing/test_function_calling.py Outdated
Comment thread tests/local_testing/test_function_calling.py Outdated
Comment thread tests/pass_through_unit_tests/test_anthropic_messages_prompt_caching.py Outdated
@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Replace hardcoded Bedrock Anthropic model IDs in 2 live test files with
required env vars set in CircleCI project env vars. Future AWS EOLs of
Bedrock Anthropic models become CircleCI UI value bumps — no PR, no
multi-file code edit (cf. PR #26721 which had to touch 16 files).

Three env vars, one per route prefix, each holding a full copy-pasteable
model path:

  BEDROCK_ANTHROPIC_MODEL          → bedrock/<id>           (default route)
  BEDROCK_ANTHROPIC_CONVERSE_MODEL → bedrock/converse/<id>  (explicit converse)
  BEDROCK_ANTHROPIC_INVOKE_MODEL   → bedrock/invoke/<id>    (explicit invoke)

Test code is os.environ[...] with no concatenation. No in-code fallback
default — files fail loud at collection (KeyError) if any env var is
missing. This avoids the dead-code trap of unused fallbacks (cf.
existing precedents BEDROCK_TEST_MODEL, LITELLM_PROXY_RESPONSES_MODEL
which silently default forever because their env vars were never set).

Scope is limited to live tests only:
  - tests/local_testing/test_function_calling.py
  - tests/pass_through_unit_tests/test_anthropic_messages_prompt_caching.py

Mocked transformation tests intentionally keep their hardcoded IDs —
the model string is opaque there and never reaches AWS.

Pre-merge: all 3 env vars must be set in CircleCI UI.
@ryan-crabbe-berri
ryan-crabbe-berri force-pushed the litellm_chore-env-driven-bedrock-test-models branch from 022b5ae to e10b14a Compare April 29, 2026 00:37
…c live-call sites

Migrate 8 additional sonnet-routed live test call sites to read the model
path from the existing `BEDROCK_ANTHROPIC_MODEL` / `BEDROCK_ANTHROPIC_INVOKE_MODEL`
env vars introduced in e10b14a. Future Anthropic-on-Bedrock EOL bumps now
take fewer file edits than they did under PR #26721.

Sites (4 files):
  tests/llm_translation/test_bedrock_completion.py
    478, 605, 633, 942, 2890   bedrock/<id>             → BEDROCK_ANTHROPIC_MODEL
  tests/local_testing/test_exceptions.py
    474                         bedrock/<id>             → BEDROCK_ANTHROPIC_MODEL
  tests/local_testing/test_streaming.py
    1244                        bedrock/<id>             → BEDROCK_ANTHROPIC_MODEL
  tests/pass_through_unit_tests/test_bedrock_tool_use_beta_header.py
    27                          bedrock/invoke/<id>      → BEDROCK_ANTHROPIC_INVOKE_MODEL

Route prefix is preserved at every site (no cross-routing).

Deliberately not migrated:
  - haiku-pinned tests (env vars resolve to sonnet) — see test_bedrock_completion.py
    haiku sites and tests/local_testing/test_timeout.py:79
  - test_bedrock_govcloud.py — uses completion_cost(), pure utility, never hits AWS
  - test_bedrock_completion.py:2038 (_transform_request), 2526 (decoder), 664
    (@pytest.mark.skip)
  - test_bedrock_completion.py:3145, 3152, 3247, 3300, 3352 — passthrough tests
    with hardcoded `endpoint=` alongside `model=`; would need a 4th env var or
    string-derivation
  - test_bedrock_anthropic_messages_test.py and test_websearch_interception_e2e.py
    — multi-site router-config refactors; deferred
  - all tests/test_litellm/* — strict unit / mocked transformation tests; the
    hardcoded model string never reaches AWS so EOLs don't break them
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Jul 29, 2026
@github-actions github-actions Bot closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant