[PR #5040] [CLOSED] fix: use per-model output token limits for Anthropic agent provider #4873

Closed
opened 2026-02-22 18:36:42 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/5040
Author: @elevatingcreativity
Created: 2/20/2026
Status: Closed

Base: masterHead: fix/anthropic-agent-max-tokens


📝 Commits (2)

  • 340bed7 fix: use per-model output token limits for Anthropic agent provider
  • b149a73 Merge branch 'master' into fix/anthropic-agent-max-tokens

📊 Changes

2 files changed (+159 additions, -2 deletions)

View changed files

server/__tests__/utils/agents/aibitat/providers/anthropic.test.js (+130 -0)
📝 server/utils/agents/aibitat/providers/anthropic.js (+29 -2)

📄 Description

Closes #5039

Bug

The Anthropic agent provider hardcodes max_tokens: 4096 for all API calls. Modern Claude models (Claude 3.5 and later) support output limits well above 4096 tokens, but the hardcoded value was set when older models had smaller limits. As a result, agent responses are silently cut off at 4096 tokens regardless of which model is selected.

Location: server/utils/agents/aibitat/providers/anthropic.jsmax_tokens: 4096 is hardcoded in both the stream() and complete() methods.

Fix

Replaces the hardcoded max_tokens: 4096 with a MODEL_MAX_OUTPUT_TOKENS lookup table mapping each Anthropic model to its actual API-enforced output token limit. Claude 3.5 models use 8192, Claude 3.7 uses 64,000, legacy models retain 4096, and any unknown or future models fall back to 4096 safely.

This also prevents 400 API errors that would occur if a hardcoded value exceeded an older model's output limit — the Anthropic API rejects requests where max_tokens exceeds the model's maximum rather than silently clamping it.

Test plan

  • Added Jest tests covering all model tiers (legacy, Claude 3.5, Claude 3.7, unknown)
  • Verified the correct max_tokens value is passed in actual API calls via mock
  • Run: jest server/__tests__/utils/agents/aibitat/providers/anthropic.test.js

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/5040 **Author:** [@elevatingcreativity](https://github.com/elevatingcreativity) **Created:** 2/20/2026 **Status:** ❌ Closed **Base:** `master` ← **Head:** `fix/anthropic-agent-max-tokens` --- ### 📝 Commits (2) - [`340bed7`](https://github.com/Mintplex-Labs/anything-llm/commit/340bed7c98ae99c74be57efbcdac60acce18e739) fix: use per-model output token limits for Anthropic agent provider - [`b149a73`](https://github.com/Mintplex-Labs/anything-llm/commit/b149a7345b2be9e5a0de8ccfc890c888376fdc38) Merge branch 'master' into fix/anthropic-agent-max-tokens ### 📊 Changes **2 files changed** (+159 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `server/__tests__/utils/agents/aibitat/providers/anthropic.test.js` (+130 -0) 📝 `server/utils/agents/aibitat/providers/anthropic.js` (+29 -2) </details> ### 📄 Description Closes #5039 ## Bug The Anthropic agent provider hardcodes `max_tokens: 4096` for all API calls. Modern Claude models (Claude 3.5 and later) support output limits well above 4096 tokens, but the hardcoded value was set when older models had smaller limits. As a result, agent responses are silently cut off at 4096 tokens regardless of which model is selected. **Location:** `server/utils/agents/aibitat/providers/anthropic.js` — `max_tokens: 4096` is hardcoded in both the `stream()` and `complete()` methods. ## Fix Replaces the hardcoded `max_tokens: 4096` with a `MODEL_MAX_OUTPUT_TOKENS` lookup table mapping each Anthropic model to its actual API-enforced output token limit. Claude 3.5 models use 8192, Claude 3.7 uses 64,000, legacy models retain 4096, and any unknown or future models fall back to 4096 safely. This also prevents 400 API errors that would occur if a hardcoded value exceeded an older model's output limit — the Anthropic API rejects requests where `max_tokens` exceeds the model's maximum rather than silently clamping it. ## Test plan - [x] Added Jest tests covering all model tiers (legacy, Claude 3.5, Claude 3.7, unknown) - [x] Verified the correct `max_tokens` value is passed in actual API calls via mock - [x] Run: `jest server/__tests__/utils/agents/aibitat/providers/anthropic.test.js` 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-22 18:36:42 -05:00
yindo changed title from [PR #5040] fix: use per-model output token limits for Anthropic agent provider to [PR #5040] [CLOSED] fix: use per-model output token limits for Anthropic agent provider 2026-06-05 15:20:48 -04:00
yindo closed this issue 2026-06-05 15:20:49 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#4873