Unable to use Devstral Small: error due to max tokens #670

Closed
opened 2026-02-16 17:27:50 -05:00 by yindo · 2 comments
Owner

Originally created by @KTibow on GitHub (Jul 12, 2025).

Originally assigned to: @thdxr on GitHub.

Some models (Devstral Small on Chutes, Mercury Coder, many more near the bottom of this list) have context lengths of 32k tokens. Since opencode always sets max tokens to 32k and sends more tokens as context, errors result:

Image

This is likely due to an incorrect context length in models.dev. opencode should adapt its request to use a shorter max tokens (in case the data is incorrect) and/or switch to using data from the models endpoint (always use correct data).

Originally created by @KTibow on GitHub (Jul 12, 2025). Originally assigned to: @thdxr on GitHub. Some models (Devstral Small on Chutes, Mercury Coder, many more near the bottom of [this list](https://openrouter.ai/models?order=context-high-to-low)) have context lengths of 32k tokens. Since opencode always sets max tokens to 32k and sends more tokens as context, errors result: <img width="1651" height="258" alt="Image" src="https://github.com/user-attachments/assets/56fd9a40-d365-4841-a8a9-e2b626deb735" /> This is likely due to an incorrect context length in models.dev. opencode should adapt its request to use a shorter max tokens (in case the data is incorrect) and/or switch to using data from the models endpoint (always use correct data).
yindo closed this issue 2026-02-16 17:27:50 -05:00
Author
Owner

@thdxr commented on GitHub (Jul 13, 2025):

can you set output tokens number to be 16K or something smaller?

@thdxr commented on GitHub (Jul 13, 2025): can you set output tokens number to be 16K or something smaller?
Author
Owner

@KTibow commented on GitHub (Jul 13, 2025):

That would theoretically fix it, but ideally https://github.com/sst/models.dev/pull/49 would be merged and then something like this would be added:

- const outputLimit = Math.min(model.info.limit.output, OUTPUT_TOKEN_MAX) || OUTPUT_TOKEN_MAX
+ let outputLimit = OUTPUT_TOKEN_MAX;
+ if (model.info.limit.output && model.info.limit.output < outputLimit) outputLimit = model.info.limit.output;
+ const tokens = previous && previous.tokens && (previous.tokens.input + previous.tokens.cache.read + previous.tokens.cache.write + previous.tokens.output);
+ const tokensRemaining = model.info.limit.input - tokens;
+ if (tokensRemaining && tokensRemaining < outputLimit) outputLimit = tokensRemaining;
@KTibow commented on GitHub (Jul 13, 2025): That would theoretically fix it, but ideally https://github.com/sst/models.dev/pull/49 would be merged and then something like this would be added: ```diff - const outputLimit = Math.min(model.info.limit.output, OUTPUT_TOKEN_MAX) || OUTPUT_TOKEN_MAX + let outputLimit = OUTPUT_TOKEN_MAX; + if (model.info.limit.output && model.info.limit.output < outputLimit) outputLimit = model.info.limit.output; + const tokens = previous && previous.tokens && (previous.tokens.input + previous.tokens.cache.read + previous.tokens.cache.write + previous.tokens.output); + const tokensRemaining = model.info.limit.input - tokens; + if (tokensRemaining && tokensRemaining < outputLimit) outputLimit = tokensRemaining; ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#670