can1357/oh-my-pi · error
Provider ${providerName}, model ${modelDef.id}: invalid cont
Error message
Provider ${providerName}, model ${modelDef.id}: invalid contextWindow What it means
Thrown by validateProviderConfiguration in models-config mode when a model declares a contextWindow that is not a positive number (zero or negative). The context window bounds prompt sizing and truncation logic; a non-positive value would break token budgeting. Runtime registration skips this check.
Source
Thrown at packages/coding-agent/src/config/models-config.ts:98
if (mode === "models-config" && config.discovery && !config.api && config.discovery.type !== "proxy") {
throw new Error(`Provider ${providerName}: "api" is required when discovery is enabled at provider level.`);
}
for (const modelDef of models) {
if (!hasProviderApi && !modelDef.api) {
throw new Error(
mode === "runtime-register"
? `Provider ${providerName}, model ${modelDef.id}: no "api" specified.`
: `Provider ${providerName}, model ${modelDef.id}: no "api" specified. Set at provider or model level.`,
);
}
if (!modelDef.id) {
throw new Error(`Provider ${providerName}: model missing "id"`);
}
if (mode === "models-config") {
if (modelDef.contextWindow !== undefined && modelDef.contextWindow <= 0) {
throw new Error(`Provider ${providerName}, model ${modelDef.id}: invalid contextWindow`);
}
if (modelDef.maxTokens !== undefined && modelDef.maxTokens <= 0) {
throw new Error(`Provider ${providerName}, model ${modelDef.id}: invalid maxTokens`);
}
}
}
}
export const ModelsConfigFile = new ConfigFile<ModelsConfig>("models", {
kind: "deferred",
resolve: getModelsConfigSchema,
}).withValidation("models", config => {
const providers = config.providers ?? {};
for (const providerName in providers) {
const providerConfig = providers[providerName];
validateProviderConfiguration(
providerName,
{View on GitHub (pinned to 9690622007)
Solutions
- Set contextWindow to the model's real positive token limit
- Remove the contextWindow field entirely if unknown (it is optional)
- Fix templates/env vars so substitution yields a positive integer
Example fix
// before
{ "id": "my-model", "contextWindow": 0 }
// after
{ "id": "my-model", "contextWindow": 128000 } Defensive patterns
Strategy: validation
Validate before calling
function assertContextWindows(cfg) {
(cfg.models ?? []).forEach(m => {
if (m.contextWindow !== undefined && m.contextWindow <= 0) throw new Error(`${m.id}: contextWindow must be > 0`);
});
} Type guard
function hasPositiveContextWindow(m) { return m.contextWindow === undefined || (Number.isFinite(m.contextWindow) && m.contextWindow > 0); } Try / catch
try { registerProvider(cfg); } catch (e) { if (String(e).includes('invalid contextWindow')) { logger.error('Fix non-positive contextWindow', { provider: cfg.name }); } else throw e; } Prevention
- Omit contextWindow when unknown instead of writing 0
- Sanity-check generated configs: all numeric limits must be positive integers
- Guard template substitutions against empty values resolving to 0
When it happens
Trigger: Loading a models-config file where any model entry has contextWindow set to 0, a negative number, or a value computed to be <= 0.
Common situations: Hand-edited configs with placeholder values left at 0; templated configs where an env-substituted value resolved to empty/0; unit mistakes (writing context window in billions vs tokens).
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Provider ${providerName}, model ${modelDef.id}: invalid maxT
- Failed to load tree-sitter language: {err}
- Destination option ${key} must be a string
- Destination option ${key} must be a finite number
- Destination option ${key} must be a boolean
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/2cb1d860d69a0cb1.
Report an issue: GitHub.