Skip to content

feat(api): add no_reasoning flag - #1080

Merged
steebchen merged 2 commits into
mainfrom
terragon/add-no-reasoning-flag-i2x2ks
Oct 26, 2025
Merged

steebchen merged 2 commits into
mainfrom
terragon/add-no-reasoning-flag-i2x2ks

Conversation

@steebchen

@steebchen steebchen commented Oct 26, 2025

Copy link
Copy Markdown
Member

Summary

  • Introduces a new no_reasoning boolean flag for auto routing to exclude reasoning models from selection.
  • Adds validation and error handling so that if no non-reasoning models are available, the API returns a clear 400 error.
  • Updates documentation with guidance and usage example for the new flag.

Changes

API / Completions

  • Added no_reasoning: boolean().optional().default(false) to the completions schema.
    • Description: "When used with auto routing, exclude reasoning models from selection".
    • This flag only affects auto routing when model is set to "auto".

Auto-routing logic

  • When auto routing is used and no_reasoning is true, non-reasoning providers are preferred; reasoning models are excluded from selection.
  • If no non-reasoning models are available that meet the request requirements and no_reasoning is true, the API now returns a 400 error with a descriptive message:
    • "No non-reasoning models are available for auto routing. Remove no_reasoning parameter or use a specific model."
  • If no suitable models are found (and no_reasoning is not satisfied), behavior falls back to existing error or fallback paths (e.g., using the cheapest allowed model if applicable).
  • Existing behavior for free_models_only and reasoning model handling remains intact, with the new exclusion logic applied when no_reasoning is requested.

Documentation

  • Updated docs at apps/docs/content/features/routing.mdx with a new section:
    • Exclude Reasoning Models
    • Example curl request demonstrating how to set no_reasoning: true with model: "auto".
    • Note: The no_reasoning parameter only works with auto routing ("model": "auto"). If none non-reasoning models are available, the API will return an error.

Documentation Example (Snippet)

  • Added a no_reasoning example in routing docs showing how to call the API with no_reasoning: true to exclude reasoning models.

Test plan

  • Verify that auto routing excludes reasoning models when no_reasoning is true
  • Verify that a descriptive 400 error is returned when no non-reasoning models are available
  • Ensure default behavior is unchanged when no_reasoning is not provided or is false
  • Validate the new documentation section renders correctly and the curl example works as documented

Notes

  • The new flag is opt-in and only affects auto routing. If you specify a concrete model or if there are no non-reasoning models available, behavior will follow the existing routing/error handling mechanisms.

🌿 Generated by Terry


ℹ️ Tag @terragon-labs to ask questions and address PR feedback

📎 Task: https://www.terragonlabs.com/task/ab95c290-3e3a-4246-ad31-c971ae8c5862

Summary by CodeRabbit

  • New Features

    • Added a no_reasoning option for completions to exclude reasoning-enabled models during auto-routing; surfaces clear errors when no suitable models remain.
  • Documentation

    • Expanded Auto Routing docs with an Optimized Auto Routing section, examples for reasoning_effort and no_reasoning, and updated guidance (includes large-context request behavior).

…om auto routing

- Introduced `no_reasoning` boolean parameter in chat completions API.
- When set to true with `model: auto`, excludes reasoning models from selection.
- Returns an error if no suitable non-reasoning models are available.
- Updated documentation with usage example and parameter description.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
@bunnyshell

bunnyshell Bot commented Oct 26, 2025

Copy link
Copy Markdown

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

@coderabbitai

coderabbitai Bot commented Oct 26, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Added a no_reasoning boolean to the completions API and validation, updated auto-routing to exclude reasoning-enabled providers when set, surfaced 400 errors when no non-reasoning models are available, and expanded docs with examples and callouts for reasoning-related routing options.

Changes

Cohort / File(s) Change Summary
Documentation
apps/docs/content/features/routing.mdx
Added/rewrote Auto Routing content: new "Reasoning models only" and "Exclude Reasoning Models" sections, examples for reasoning_effort and no_reasoning, updated callouts and wording.
API Schema & Routing
apps/gateway/src/chat/chat.ts
Added no_reasoning: z.boolean().optional().default(false) to completions request schema; included no_reasoning in parsed validation data; updated auto-routing/provider-filtering to exclude reasoning-enabled providers when set; added 400 error branches when no suitable non-reasoning models are available.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API as API Handler
    participant Router as Auto-Router
    participant Provider as Provider Selector

    Client->>API: POST /completions\n{ no_reasoning: true, reasoning_effort: ... }
    API->>API: Validate request (includes no_reasoning)
    API->>Router: Invoke auto-routing with flags

    rect rgb(240,248,255)
      note over Router: Filter providers\n- apply free_models_only\n- apply reasoning_effort\n- if no_reasoning -> exclude reasoning-enabled
      Router->>Router: Filter candidate providers
    end

    alt non-reasoning providers found
      Router->>Provider: Select best non-reasoning model
      Provider-->>Client: Stream/Return completion
    else none available
      Router-->>Client: 400 Error — No suitable non-reasoning models
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Changes touch validation schema, request parsing, and routing logic; includes branching/error handling.
  • Review focus: provider filtering conditions, interaction with existing reasoning_effort and free_models_only logic, and correctness of 400 error paths.
  • Files needing extra attention: apps/gateway/src/chat/chat.ts (logic branches) and apps/docs/content/features/routing.mdx (accuracy of examples and callouts).

Possibly related PRs

Suggested reviewers

  • smakosh

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "feat(api): add no_reasoning flag" directly and accurately describes the main change introduced in this pull request. The core feature being added is a new no_reasoning boolean parameter to the completions API schema, which the title clearly communicates. The title is concise, uses conventional commit formatting, avoids noise or vague terminology, and is specific enough that a developer scanning the commit history would immediately understand that a new API flag for excluding reasoning models has been introduced. While the PR also includes documentation updates and routing logic changes, these are implementation details that support the primary feature being added.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch terragon/add-no-reasoning-flag-i2x2ks

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between baaa836 and 6069462.

📒 Files selected for processing (1)
  • apps/docs/content/features/routing.mdx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/docs/content/features/routing.mdx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot changed the title Add no_reasoning flag to auto-routing to exclude reasoning models feat(api): add no_reasoning flag Oct 26, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/gateway/src/chat/chat.ts (2)

976-987: Consider improving error message clarity when both flags are set.

When both free_models_only and no_reasoning are true and no models are found, only the free_models_only error (lines 976-981) will be shown due to the else-if chain. While technically correct, this could be confusing if the actual issue is that no free non-reasoning models exist.

Consider consolidating or enhancing the error message to account for both flags:

-			} else if (free_models_only) {
+			} else if (free_models_only && no_reasoning) {
+				// If no free models are available, return error
+				throw new HTTPException(400, {
+					message:
+						"No free non-reasoning models are available for auto routing. Remove free_models_only or no_reasoning parameters or use a specific model.",
+				});
+			} else if (free_models_only) {
 				// If no free models are available, return error
 				throw new HTTPException(400, {

990-1001: Same error message clarity issue applies here.

This error handling block has the same issue as lines 976-987. When both free_models_only and no_reasoning are true, only the free_models_only error will be shown. The same consolidation approach suggested in the previous comment would improve clarity here as well.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cdaa52 and baaa836.

📒 Files selected for processing (2)
  • apps/docs/content/features/routing.mdx (1 hunks)
  • apps/gateway/src/chat/chat.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Always use top-level import; never use require() or dynamic import()

Files:

  • apps/gateway/src/chat/chat.ts
apps/{gateway,api}/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

apps/{gateway,api}/**/*.ts: Use Hono for HTTP routing in Gateway and API services
Use Zod schemas for request/response validation in server routes

Files:

  • apps/gateway/src/chat/chat.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Never use any or as any in this TypeScript project unless absolutely necessary
Always use top-level import; do not use require or dynamic import()

Files:

  • apps/gateway/src/chat/chat.ts
{apps/{api,gateway}/**/*.ts,packages/db/**/*.ts}

📄 CodeRabbit inference engine (CLAUDE.md)

For read operations, use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/gateway/src/chat/chat.ts
🧬 Code graph analysis (1)
apps/gateway/src/chat/chat.ts (1)
packages/models/src/models.ts (1)
  • ProviderModelMapping (23-120)
🔇 Additional comments (4)
apps/gateway/src/chat/chat.ts (3)

228-232: LGTM! Schema definition follows best practices.

The no_reasoning parameter definition is consistent with the free_models_only parameter above it, using appropriate types and defaults.


395-395: LGTM! Parameter extraction is correct.

The no_reasoning parameter is properly extracted from the validation result alongside other parameters.


912-918: LGTM! Filtering logic correctly excludes reasoning models.

The implementation properly filters out reasoning-capable providers when no_reasoning is true, and the placement within the suitableProviders filter ensures this happens before price calculations.

apps/docs/content/features/routing.mdx (1)

123-143: LGTM! Documentation is clear and well-structured.

The new documentation section effectively explains the no_reasoning parameter, provides a practical curl example, and appropriately warns users about its limitations. The structure and style are consistent with the existing documentation.

Clarified the explanation of optimized auto routing and added details on specifying reasoning models and excluding reasoning models.
@steebchen
steebchen added this pull request to the merge queue Oct 26, 2025
Merged via the queue into main with commit aa8b533 Oct 26, 2025
14 checks passed
@steebchen
steebchen deleted the terragon/add-no-reasoning-flag-i2x2ks branch October 26, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant