Detect OpenAI Reasoning Models and Adjust Request Payload

Open Beginner friendly
#176 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

Start in packages/models/src/providers/openai.ts, where the issue says the request payload is built, and add the model detection helper and conditional payload fields described in the issue. First inspect the existing payload construction and nearby tests, then add coverage for reasoning and standard model branches. Done means both branches use the specified fields and prompt role, with the requested typecheck, test, and lint commands passing.

Written by the indexing model from the issue text.

Description

bug good first issue

Goal

Add a helper function that detects whether an OpenAI model identifier refers to a reasoning model, and use it to conditionally adjust the request payload sent in packages/models/src/providers/openai.ts.

Background

OpenAI reasoning models (o1, o3, o3-mini, o4-mini, and future variants) reject the temperature parameter and require max_completion_tokens instead of max_tokens. The current adapter sends both unconditionally, causing HTTP 400 errors for any reasoning model.

This sub-issue is part of the parent issue: OpenAI adapter incompatible with reasoning models.

What to Build

Add an isOpenAIReasoningModel(model: string): boolean helper in the openai provider:

function isOpenAIReasoningModel(model: string): boolean {
  const lower = model.toLowerCase();
  return (
    /^o\d/.test(lower) ||            // o1, o3, o3-mini, o4-mini, o5, etc.
    lower.includes("-reasoning") ||   // possible future naming convention
    lower.startsWith("gpt-6")         // gpt-6 and variants when in reasoning mode
  );
}

Then update the body payload construction to branch on isReasoning:

const isReasoning = isOpenAIReasoningModel(model);

const bodyPayload: Record<string, unknown> = {
  model,
  messages: [
    { role: isReasoning ? "developer" : "system", content: prompts.system },
    { role: "user", content: prompts.user },
  ],
  ...(isReasoning
    ? { max_completion_tokens: effectiveCeiling }
    : { temperature, max_tokens: effectiveCeiling }),
  response_format: { type: "json_object" },
};

Done When

  • isOpenAIReasoningModel correctly identifies o-series and gpt-6 models
  • Standard models (gpt-4o, gpt-5, custom endpoints) return false and are unaffected
  • Reasoning models receive max_completion_tokens and no temperature
  • Standard models receive temperature and max_tokens as before
  • role: "developer" is used for the system prompt on reasoning models
  • Unit tests cover the detection helper and both branches of the payload builder
  • npm run typecheck, npm test, and npm run lint all pass
Dominant language
TypeScript
Stars
125
Forks
23
Avg merge
2d 13h
Merged PRs (30d)
12

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from devarshishimpi/codra

All issues in devarshishimpi/codra

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.