← Back to PRs

#20104: Fix Anthropic 1M model ID: strip -1m suffix before API call

by Clawborn open 2026-02-18 14:42 View on GitHub →
agents size: S trusted-contributor
## Problem When using the `-1m` model ID convention (e.g. `claude-opus-4-6-1m`), the suffix is sent directly to the Anthropic API, resulting in a 404 error. The API doesn't recognize `claude-opus-4-6-1m` as a valid model name. The codebase already has partial 1M support (`isAnthropic1MModel()`, beta header injection), but the model ID wasn't being normalized before the API call. ## Fix - Strip `-1m` suffix from the model ID in `createAnthropicBetaHeadersWrapper` before forwarding to the Anthropic API - Auto-detect `-1m` suffix to inject the `context-1m-2025-08-07` beta header without requiring an explicit `context1m` param - `isAnthropic1MModel()` now recognizes `-1m` suffixed model IDs (strips suffix before prefix check) ## Testing 6 new tests covering: - Suffix stripping for Opus and Sonnet models - Case-insensitive suffix handling - Auto-injection of beta header from suffix - Non-anthropic providers are not affected - Explicit `context1m` param still works without suffix Fixes #20079 <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR fixes a 404 error when using the `-1m` model ID convention (e.g., `claude-opus-4-6-1m`) by stripping the `-1m` suffix before sending the model ID to the Anthropic API, and auto-detecting the suffix to inject the `context-1m-2025-08-07` beta header. The change completes the existing partial 1M support in the codebase. - Two new helper functions (`stripAnthropic1MSuffix`, `hasAnthropic1MSuffix`) centralize suffix detection and removal logic - `isAnthropic1MModel()` updated to strip the suffix before checking model prefixes - `resolveAnthropicBetas()` now auto-detects `-1m` suffix in addition to the explicit `context1m` param - `createAnthropicBetaHeadersWrapper()` strips the `-1m` suffix from the model object before forwarding to the underlying stream function - 6 well-structured tests covering suffix stripping, case-insensitive handling, auto-injection, and provider isolation - **Issue**: `stripAnthropic1MSuffix` doesn't `.trim()` while `hasAnthropic1MSuffix` does, creating an inconsistency that could cause the suffix to not be stripped when it's detected - **Issue**: Non-opus/sonnet models with `-1m` suffix (e.g., `claude-haiku-3-5-1m`) will still 404 since the suffix is only stripped inside the beta headers wrapper, which isn't created when 1M is unsupported <h3>Confidence Score: 3/5</h3> - This PR solves the main problem but has minor correctness issues worth addressing before merge. - The core fix is sound and well-tested for the primary use case (opus/sonnet with -1m suffix). However, the trim inconsistency between stripAnthropic1MSuffix and hasAnthropic1MSuffix could cause the suffix to remain unstripped in edge cases, and unsupported model types with -1m suffix will still 404 without clear user feedback beyond a warning log. - src/agents/pi-embedded-runner/extra-params.ts - review the trim inconsistency and unsupported model edge case <sub>Last reviewed commit: 03048c4</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs