Skip to content

Commit f43d25d

Browse files
authored
Merge pull request router-for-me#496 from kunish/fix/copilot-premium-request-inflation
fix(copilot): prevent intermittent context overflow for Claude models
2 parents a279192 + 578c312 commit f43d25d

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

internal/registry/model_definitions.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ func LookupStaticModelInfo(modelID string) *ModelInfo {
323323
return nil
324324
}
325325

326+
// defaultCopilotClaudeContextLength is the conservative prompt token limit for
327+
// Claude models accessed via the GitHub Copilot API. Individual accounts are
328+
// capped at 128K; business accounts at 168K. When the dynamic /models API fetch
329+
// succeeds, the real per-account limit overrides this value. This constant is
330+
// only used as a safe fallback.
331+
const defaultCopilotClaudeContextLength = 128000
332+
326333
// GetGitHubCopilotModels returns the available models for GitHub Copilot.
327334
// These models are available through the GitHub Copilot API at api.githubcopilot.com.
328335
func GetGitHubCopilotModels() []*ModelInfo {
@@ -534,7 +541,7 @@ func GetGitHubCopilotModels() []*ModelInfo {
534541
Type: "github-copilot",
535542
DisplayName: "Claude Haiku 4.5",
536543
Description: "Anthropic Claude Haiku 4.5 via GitHub Copilot",
537-
ContextLength: 200000,
544+
ContextLength: defaultCopilotClaudeContextLength,
538545
MaxCompletionTokens: 64000,
539546
SupportedEndpoints: []string{"/chat/completions"},
540547
},
@@ -546,7 +553,7 @@ func GetGitHubCopilotModels() []*ModelInfo {
546553
Type: "github-copilot",
547554
DisplayName: "Claude Opus 4.1",
548555
Description: "Anthropic Claude Opus 4.1 via GitHub Copilot",
549-
ContextLength: 200000,
556+
ContextLength: defaultCopilotClaudeContextLength,
550557
MaxCompletionTokens: 32000,
551558
SupportedEndpoints: []string{"/chat/completions"},
552559
},
@@ -558,7 +565,7 @@ func GetGitHubCopilotModels() []*ModelInfo {
558565
Type: "github-copilot",
559566
DisplayName: "Claude Opus 4.5",
560567
Description: "Anthropic Claude Opus 4.5 via GitHub Copilot",
561-
ContextLength: 200000,
568+
ContextLength: defaultCopilotClaudeContextLength,
562569
MaxCompletionTokens: 64000,
563570
SupportedEndpoints: []string{"/chat/completions"},
564571
Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}},
@@ -571,7 +578,7 @@ func GetGitHubCopilotModels() []*ModelInfo {
571578
Type: "github-copilot",
572579
DisplayName: "Claude Opus 4.6",
573580
Description: "Anthropic Claude Opus 4.6 via GitHub Copilot",
574-
ContextLength: 200000,
581+
ContextLength: defaultCopilotClaudeContextLength,
575582
MaxCompletionTokens: 64000,
576583
SupportedEndpoints: []string{"/chat/completions"},
577584
Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}},
@@ -584,7 +591,7 @@ func GetGitHubCopilotModels() []*ModelInfo {
584591
Type: "github-copilot",
585592
DisplayName: "Claude Sonnet 4",
586593
Description: "Anthropic Claude Sonnet 4 via GitHub Copilot",
587-
ContextLength: 200000,
594+
ContextLength: defaultCopilotClaudeContextLength,
588595
MaxCompletionTokens: 64000,
589596
SupportedEndpoints: []string{"/chat/completions"},
590597
Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}},
@@ -597,7 +604,7 @@ func GetGitHubCopilotModels() []*ModelInfo {
597604
Type: "github-copilot",
598605
DisplayName: "Claude Sonnet 4.5",
599606
Description: "Anthropic Claude Sonnet 4.5 via GitHub Copilot",
600-
ContextLength: 200000,
607+
ContextLength: defaultCopilotClaudeContextLength,
601608
MaxCompletionTokens: 64000,
602609
SupportedEndpoints: []string{"/chat/completions"},
603610
Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}},
@@ -610,7 +617,7 @@ func GetGitHubCopilotModels() []*ModelInfo {
610617
Type: "github-copilot",
611618
DisplayName: "Claude Sonnet 4.6",
612619
Description: "Anthropic Claude Sonnet 4.6 via GitHub Copilot",
613-
ContextLength: 200000,
620+
ContextLength: defaultCopilotClaudeContextLength,
614621
MaxCompletionTokens: 64000,
615622
SupportedEndpoints: []string{"/chat/completions"},
616623
Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}},

internal/registry/model_registry.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,16 @@ func (r *ModelRegistry) convertModelToMap(model *ModelInfo, handlerType string)
11771177
"dynamic_allowed": model.Thinking.DynamicAllowed,
11781178
}
11791179
}
1180+
// Include context limits so Claude Code can manage conversation
1181+
// context correctly, especially for Copilot-proxied models whose
1182+
// real prompt limit (128K-168K) is much lower than the 1M window
1183+
// that Claude Code may assume for Opus 4.6 with 1M context enabled.
1184+
if model.ContextLength > 0 {
1185+
result["context_length"] = model.ContextLength
1186+
}
1187+
if model.MaxCompletionTokens > 0 {
1188+
result["max_completion_tokens"] = model.MaxCompletionTokens
1189+
}
11801190
return result
11811191

11821192
case "gemini":

0 commit comments

Comments
 (0)