From c6529c8a7d3ddfe19bf58c06d460dc0a988eb10c Mon Sep 17 00:00:00 2001 From: ThomasOrtiz3647 <58230587-ThomasOrtiz3647@users.noreply.replit.com> Date: Sun, 26 Apr 2026 14:52:31 +0000 Subject: [PATCH] Add different effort levels for models Add model variants for OpenAI and Anthropic APIs to support varying levels of reasoning effort, allowing clients to select effort by model name. Replit-Commit-Author: Agent Replit-Commit-Session-Id: dcd090ca-935a-42ae-8db4-503e1bbe165a Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 9c490fc7-dd25-43e2-b6d5-ada682953c75 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/40608c50-a053-47e8-aa03-1bdcc1a2698b/dcd090ca-935a-42ae-8db4-503e1bbe165a/ZBSB1hW Replit-Helium-Checkpoint-Created: true --- artifacts/api-server/src/routes/proxy.ts | 76 +++++++++++++++++++----- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/artifacts/api-server/src/routes/proxy.ts b/artifacts/api-server/src/routes/proxy.ts index 1f91771..79e690a 100644 --- a/artifacts/api-server/src/routes/proxy.ts +++ b/artifacts/api-server/src/routes/proxy.ts @@ -14,16 +14,43 @@ const anthropic = new Anthropic({ apiKey: process.env["AI_INTEGRATIONS_ANTHROPIC_API_KEY"], }); -const MODELS = [ - { id: "gpt-5.2", provider: "openai" }, - { id: "gpt-5-mini", provider: "openai" }, - { id: "gpt-5-nano", provider: "openai" }, - { id: "o4-mini", provider: "openai" }, - { id: "o3", provider: "openai" }, - { id: "claude-opus-4-6", provider: "anthropic" }, - { id: "claude-sonnet-4-6", provider: "anthropic" }, - { id: "claude-haiku-4-5", provider: "anthropic" }, -] as const; +const REASONING_BASE_MODELS = [ + { id: "gpt-5.2", provider: "openai" as const }, + { id: "gpt-5-mini", provider: "openai" as const }, + { id: "gpt-5-nano", provider: "openai" as const }, + { id: "o4-mini", provider: "openai" as const }, + { id: "o3", provider: "openai" as const }, + { id: "claude-opus-4-6", provider: "anthropic" as const }, + { id: "claude-sonnet-4-6", provider: "anthropic" as const }, + { id: "claude-haiku-4-5", provider: "anthropic" as const }, +]; + +const EFFORT_LEVELS = ["minimal", "low", "medium", "high"] as const; +type EffortLevel = (typeof EFFORT_LEVELS)[number]; + +interface ModelEntry { + id: string; + provider: "openai" | "anthropic"; + baseModel: string; + effort: EffortLevel | null; +} + +const MODELS: ModelEntry[] = REASONING_BASE_MODELS.flatMap((m) => { + const variants: ModelEntry[] = [ + { id: m.id, provider: m.provider, baseModel: m.id, effort: null }, + ]; + for (const effort of EFFORT_LEVELS) { + variants.push({ + id: `${m.id}-${effort}`, + provider: m.provider, + baseModel: m.id, + effort, + }); + } + return variants; +}); + +const MODEL_INDEX: Map = new Map(MODELS.map((m) => [m.id, m])); function authorize(req: Request, res: Response): boolean { const expected = process.env["PROXY_API_KEY"]; @@ -115,19 +142,36 @@ router.post("/chat/completions", async (req, res) => { return; } - const stream = body.stream === true; + const requestedId = body.model; + const entry = MODEL_INDEX.get(requestedId); - if (isOpenAIModel(body.model)) { - await handleOpenAI(req, res, body, stream); - } else if (isAnthropicModel(body.model)) { - await handleAnthropic(req, res, body, stream); + let provider: "openai" | "anthropic"; + if (entry) { + body.model = entry.baseModel; + if (entry.effort && !body.reasoning_effort) { + body.reasoning_effort = entry.effort; + } + provider = entry.provider; + } else if (isOpenAIModel(requestedId)) { + provider = "openai"; + } else if (isAnthropicModel(requestedId)) { + provider = "anthropic"; } else { res.status(400).json({ error: { - message: `Unsupported model: ${body.model}`, + message: `Unsupported model: ${requestedId}`, type: "invalid_request_error", }, }); + return; + } + + const stream = body.stream === true; + + if (provider === "openai") { + await handleOpenAI(req, res, body, stream); + } else { + await handleAnthropic(req, res, body, stream); } });