1197
1198
private async _refreshModels(): Promise<void> {
1200
>
if (usageSource === 'openai') {
1201
await this._refreshOpenAIModels();
1202
return;
1203
}
1205
>
if (!token) {
1206
this._models.set([], undefined);
1207
return;
1208
}
1210
>
const userAgent = `${USER_AGENT_PREFIX}/${this._productService.version}`;
1211
>
const all = await this._copilotApiService.models(token, { headers: { 'User-Agent': userAgent }, suppressIntegrationId: true });
1212
>
if (this._usageSource !== usageSource || this._githubToken !== token) {
1213
return;
1214
}
1215
>
const configSchema = this._createReasoningEffortConfigSchema();
codexAgent.ts
1216
>
// Codex talks to every model through the `vscode-proxy` custom model
1217
>
// provider with `wire_api="responses"` (see CodexProxyService), so it
1218
>
// can only drive models that expose Copilot CAPI's OpenAI-shaped
1219
>
// Responses endpoint. Filter the catalog to those advertising
1220
>
// `/responses` in `supported_endpoints` (this drops Anthropic
1221
>
// `/v1/messages` and chat-completions-only models, which codex cannot
1222
>
// use). The chosen id is forwarded straight through; CAPI remains the
1223
>
// authority on what the token may actually use.
1224
>
const models = all
1225
>
.filter(m => m.supported_endpoints?.includes(CODEX_RESPONSES_ENDPOINT))
1226
>
.sort((a, b) => Number(b.is_chat_default) - Number(a.is_chat_default))
1227
>
.map((m): IAgentModelInfo => ({
1228
>
provider: this.id,
1229
>
id: m.id,
1230
>
name: m.name ?? m.id,
1231
>
maxContextWindow: m.capabilities?.limits?.max_context_window_tokens,
1232
>
maxOutputTokens: m.capabilities?.limits?.max_output_tokens,
1233
>
maxPromptTokens: m.capabilities?.limits?.max_prompt_tokens,
1234
>
supportsVision: !!m.capabilities?.supports?.vision,
1235
>
configSchema,
1236
>
policyState: m.policy?.state as PolicyState | undefined,
1237
>
_meta: createPricingMetaFromBilling(
1238
>
normalizeCAPIBilling(m.billing),
1239
>
typeof m.model_picker_price_category === 'string'
1240
? m.model_picker_price_category
1242
>
),
1243
>
}));
1244
>
this._models.set(models, undefined);
1245
>
} catch (err) {
1246
>
this._logService.warn(`[Codex] Failed to refresh models: ${err instanceof Error ? err.message : String(err)}`);
1247
>
// Keep the last known-good catalog. Usage-source changes clear the
1248
>
// list in `_applyUsageSourceChange`; a transient periodic failure
1249
>
// must not make every model disappear.
1250
>
}
1251
>
}
1252
1253
private async _refreshOpenAIModels(): Promise<void> {