Skip to content

openai: ChatGPT OAuth reports 400k context for long-context models #47646

Closed

Description

@abeisleem

Summary

When OpenAI models are used through a ChatGPT OAuth connection, OpenCode overwrites their effective context limits with 400,000 tokens. This affects multiple long-context OpenAI models whose catalog limits are approximately 1.05 million tokens, causing the TUI to substantially overstate context usage.

For example, approximately 140,000 tokens are shown as 35–36% usage instead of approximately 13–14%.

Environment

  • opencode version: v0.0.0-beta-19192
  • OS: Darwin 24.6.0 (arm64)
  • Terminal: Ghostty (TERM=xterm-256color, COLORTERM=truecolor)
  • Shell: /bin/zsh
  • Install/channel: beta
  • Active plugins: none found in project or global configuration

Reproduction

  1. Connect the openai provider using ChatGPT OAuth.

  2. Select a long-context OpenAI model such as openai/gpt-6-astra, openai/gpt-5.6-sol, or openai/gpt-5.5.

  3. Inspect the effective model metadata with:

    opencode2 api get /api/model |
      jq -r '.data[] | select(.providerID=="openai" and .limit.context==400000) | [.id,.limit.context,.limit.input,.limit.output] | @tsv'
  4. Grow a session to approximately 140,000 tokens.

  5. Observe the context usage percentage in the TUI.

Expected Behavior

OpenCode should use the actual context limit supported by each model and connection rather than applying a blanket 400,000-token limit.

Models whose catalog metadata declares a 1,050,000-token context should report approximately 13–14% usage at roughly 140,000 tokens.

Actual Behavior

The affected models report an effective limit of 400,000 context tokens and 272,000 input tokens. On the tested installation, this includes:

gpt-6-astra
gpt-6-astra-fast
gpt-5.6-sol
gpt-5.6-sol-fast
gpt-5.6-luna
gpt-5.6-luna-fast
gpt-5.6-terra
gpt-5.6-terra-fast
gpt-5.5
gpt-5.5-fast
gpt-5.4
gpt-5.4-fast

For example, the API reports:

{"id":"gpt-6-astra","providerID":"openai","limit":{"context":400000,"input":272000,"output":128000},"baseURL":"https://chatgpt.com/backend-api/codex"}

The TUI percentage arithmetic appears correct: it divides the latest token count by model.limit.context. The inflated percentage comes from the effective model limit.

Additional Context

The OpenAI provider's ChatGPT OAuth catalog transform applies a blanket override to eligible models:

draft.limit = { ...draft.limit, context: 400_000, input: 272_000 }

This discards model-specific catalog limits. For example, several affected models declare:

{"context":1050000,"input":922000,"output":128000}

This is consistently reproducible across multiple OpenAI models connected through ChatGPT OAuth. No user-defined model or provider limit overrides are configured.

Activity

  1. github-actions commented on Sep 6, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. russrapper15-png commented on Sep 6, 2026

    @russrapper15-png
  3. AleksQuantum commented on Sep 30, 2026

    @AleksQuantum

    The issue still seems to be present

  4. marwasha commented on Oct 1, 2026

    @marwasha

    This issue just appeared to me, v1 had the full 1mil context window

  5. maxiedaniels commented on Oct 1, 2026

    @maxiedaniels

    Ya just migrated to v2, this is happening for me too. I had 6.1 trace the cause:

    """
    OpenCode v2.0.21, opencode.provider.openai registers a model transform that, when its OpenAI OAuth connection is active, applies this to eligible OpenAI models:

    js
    model.limit = {
    ...model.limit,
    context: 400000,
    input: 272000
    }
    That includes gpt-6.1-sol. It preserves the catalog’s 128K output limit but overwrites its context and input limits.
    """

  6. barreiroleo commented on Oct 1, 2026

    @barreiroleo

    Ya just migrated to v2, this is happening for me too. I had 6.1 trace the cause:

    """ OpenCode v2.0.21, opencode.provider.openai registers a model transform that, when its OpenAI OAuth connection is active, applies this to eligible OpenAI models:

    js model.limit = { ...model.limit, context: 400000, input: 272000 } That includes gpt-6.1-sol. It preserves the catalog’s 128K output limit but overwrites its context and input limits. """

    Just in case, the workaround for 6.1 #44821 (comment)

  7. marwasha commented on Oct 4, 2026

    @marwasha

    Proposed V2 fix: #53080. It removes the blanket ChatGPT OAuth 400K/272K override so each model retains its catalog context/input limits, with regression coverage for long-context models, a fast alias, and a smaller-context model. The regression fails before the fix and passes afterward; focused tests and the full local lint/typecheck pass. The PR is ready for maintainer review.

    Update: a Linux x64 build of PR head dc65500 reports 1,050,000 context / 922,000 input tokens on the ChatGPT route for GPT-6.1 Sol, Astra, Astra Fast, GPT-5.6 Sol, and GPT-5.5. This verifies effective metadata, not endpoint capacity.

    Independent confirmation from another affected user would help: if you test the PR, please share the model, ChatGPT plan, effective limits, and whether ordinary longer sessions work without premature compaction or context errors. Please omit credentials and private prompts; there is no need to run a costly maximum-context probe.

  8. marwasha commented on Oct 4, 2026

    @marwasha

    Put together the following MR to address this

    #53080

  9. nicholaicascio commented on Oct 11, 2026

    @nicholaicascio

    This issue just keeps getting reported and the staff always finds a reason to close it.

    FYI the workaround that @barreiroleo posted works, and your agent can set it up easily.

  10. rekram1-node commented on Oct 12, 2026

    @rekram1-node
    Contributor

    The only reason this exists is so that people using their openai subscriptions in opencode have a similar experiences as you would in other harnesses like codex (as far as plan usage goes). Without the limit people complain that opencode eats their usage much faster because it doesn't compact as early.

    Annoyingly for everyone we didn't make it very intuitive as to why this happens, or how to disable that and that's obviously a big failure on our part and I apologize.

    On other notes, Openai is changing the way some of the quotas work so this may not be an issue at all soon:
    https://x.com/thsottiaux/status/2109430343346581527?s=20

  11. barreiroleo commented on Oct 12, 2026

    @barreiroleo
     Annoyingly for everyone we didn't make it very intuitive as to why this happens, or how to disable that and that's obviously a big failure on our part and I apologize.
    

    I don't think you guys are to blame for any of this; you're just following OpenAI's criteria. Even Codex users don't know how requests beyond X tokens were charged.

    Thanks for the follow up

  12. KaranSiddhu commented on Oct 18, 2026

    @KaranSiddhu

    uninstall the v2 and install the v1 again - really disappointed with this

  13. angelcervera commented on Oct 20, 2026

    @angelcervera

    I checked the current Codex source, and it distinguishes between the default context and the configurable maximum.

    For GPT-6 Astra, the bundled catalog declares:

    • context_window: 272,000
    • max_context_window: 872,000

    Codex also supports a model_context_window override, capped at the model’s maximum.

    I just migrated from 1.19.3, where Astra was working well for me with a 1M context window, and encountered this restriction in V2.

    This is based on source inspection, not an endpoint capacity or subscription billing test. Codex can also fetch updated model metadata from the service.

  14. dr1ss commented on Oct 21, 2026

    @dr1ss

    I confirm, Astra context is deemed smaller than what it actually is by opencode 2. starts compacting before the 272,000 mark

  15. rekram1-node commented on Oct 23, 2026

    @rekram1-node
    Contributor

    #58194

    In the next update u can opt out of it by just disabling the context cap plugin:

    { "plugins": ["-opencode.provider.openai-context-caps"] } // add this to ur global opencode config, the "-" disables the plugin
    

    We are going to keep the context limits as is (with the lower cap) to decrease ur overall spend/usage. If u want to opt out just add this to ur config, also documenting it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions