Skip to content

Fix context length calculation for OpenRouter API requests #159

@exedev-shelley

Description

@exedev-shelley

Author: tonezime
Channel: #shelley
Link: https://discord.com/channels/1405685085923049482/1450334528210993295/1487510292198850631


Issue

When using OpenRouter with a context setting of 120k tokens, the API returns an error indicating that the requested output amount is being set to the full context value (120k), rather than being treated as a separate parameter.

Error Message

This endpoint's maximum context length is 204800 tokens. However, you requested about 205432 tokens (81684 of text input, 3748 of tool input, 120000 in the output). Please reduce the length of either one [...]

Problem

The 120k context setting is being sent as the requested output amount instead of being used for context window configuration. This causes the total token request to exceed the API's maximum limit.

Expected Behavior

The context length parameter should be applied to the context window, not the output token limit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions