Skip to content

feat(provider): Add support to pass fallback provider through stream … - #880

Closed
Yaswanth-2874 wants to merge 1 commit into
juspay:releasefrom
Yaswanth-2874:BZ-1341-add-support-for-fallback-provider-through-feature-flag-or-env
Closed

Yaswanth-2874 wants to merge 1 commit into
juspay:releasefrom
Yaswanth-2874:BZ-1341-add-support-for-fallback-provider-through-feature-flag-or-env

Conversation

@Yaswanth-2874

@Yaswanth-2874 Yaswanth-2874 commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

Description

What does this PR do?
Adds support for specifying a fallback provider through stream options or environment variables, improving reliability when primary providers are unavailable.


Type of Change

  • New feature (non-breaking change which adds functionality)

Changes Made

  • Modified src/lib/neurolink.ts to support fallback provider configuration via stream options and environment variables
  • Updated src/lib/types/streamTypes.ts with new type definitions for fallback provider support
  • Added 21 lines of new functionality across 2 files

Breaking Changes

  • No breaking changes

Testing

  • Manual testing completed
  • Tested with multiple providers: primary provider, fallback provider support

Code Quality

  • Code follows the project's style guidelines (ESLint passes)
  • Code is properly formatted (Prettier applied)
  • TypeScript strict mode compliance
  • Proper error handling implemented

Commit Message Format

  • Commit message follows format: type(scope): description
  • Valid type used: feat
  • Scope specified: provider

Commit:
feat(provider): Add support to pass fallback provider through stream options or env


Dependencies

  • No dependency changes

Summary by CodeRabbit

  • New Features
    • Added support for per-call fallback provider and model configuration in streaming requests. Users can now directly specify custom fallback providers and models in request options, with automatic fallback to environment variables and model configuration defaults. This enhancement provides granular control over error recovery routing and provider selection behavior.

@vercel

vercel Bot commented Mar 17, 2026

Copy link
Copy Markdown

@BoraYaswanthReddy is attempting to deploy a commit to the Sachin Sharma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Mar 17, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9470ea2f-c40d-49a6-aad4-beeef9d9c789

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The PR introduces per-call overrides for fallback routing by extending StreamOptions with fallbackProvider and fallbackModel fields. In neurolink.ts, these options are read alongside environment variables (FALLBACK_PROVIDER, FALLBACK_MODEL) and merged with the model config route to determine the final fallback behavior, with fallbackSource tracking the override origin.

Changes

Cohort / File(s) Summary
Fallback Routing Logic
src/lib/neurolink.ts
Added per-call override resolution for fallback provider and model by merging values from enhancedOptions, environment variables, and model config. Computes fallbackSource flag to track override origin and includes fallbackModel in log payload. Applied to both initial and stream fallback paths.
Type Definition
src/lib/types/streamTypes.ts
Extended StreamOptions interface with two new optional fields: fallbackProvider?: string and fallbackModel?: string to support per-call overrides.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • murdore

Poem

🐰 With fallback routes now bending to the caller's will,
Options and env vars dance upon the sill,
Per-call overrides hop forward with grace,
While fallbackSource tracks each override's place! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main feature added: support for passing fallback provider through stream options, which aligns with the primary changes across both modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lib/neurolink.ts (1)

6166-6185: ⚠️ Potential issue | 🟠 Major

Treat empty fallback env/option values as unset.

At Line [6183] and Line [6184], ?? will treat "" as a valid override. If FALLBACK_PROVIDER/FALLBACK_MODEL (or option values) are empty strings, fallback resolution can select invalid values and fail instead of using modelConfigRoute.

Proposed fix
-    const optFallbackProvider = enhancedOptions.fallbackProvider;
-    const optFallbackModel = enhancedOptions.fallbackModel;
-    const envFallbackProvider = process.env.FALLBACK_PROVIDER;
-    const envFallbackModel = process.env.FALLBACK_MODEL;
+    const optFallbackProvider = enhancedOptions.fallbackProvider?.trim() || undefined;
+    const optFallbackModel = enhancedOptions.fallbackModel?.trim() || undefined;
+    const envFallbackProvider = process.env.FALLBACK_PROVIDER?.trim() || undefined;
+    const envFallbackModel = process.env.FALLBACK_MODEL?.trim() || undefined;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/neurolink.ts` around lines 6166 - 6185, The code uses nullish
coalescing (??) for optFallbackProvider/optFallbackModel and
envFallbackProvider/envFallbackModel which treats empty strings as valid
overrides; change the fallback selection to treat empty string as unset by
preferring the first non-empty string. Update the fallbackRoute construction
(the object merging modelConfigRoute) to use truthy checks (e.g.,
optFallbackProvider if non-empty else envFallbackProvider if non-empty else
modelConfigRoute.provider, same for model) or a small helper like
firstNonEmpty(optFallbackProvider, envFallbackProvider,
modelConfigRoute.provider) so empty "" values do not override modelConfigRoute.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/neurolink.ts`:
- Around line 6191-6195: The fallbackSource assignment is only checking
optFallbackProvider/envFallbackProvider so it reports "model_config" even when
fallbackModel is overridden; update the logic that sets fallbackSource (the
variable defined with optFallbackProvider and envFallbackProvider) to also
consider optFallbackModel and envFallbackModel: treat source as "options" if
either optFallbackProvider or optFallbackModel is set, "env" if either
envFallbackProvider or envFallbackModel is set, otherwise "model_config", and
update any related log/messages that read fallbackSource accordingly.

---

Outside diff comments:
In `@src/lib/neurolink.ts`:
- Around line 6166-6185: The code uses nullish coalescing (??) for
optFallbackProvider/optFallbackModel and envFallbackProvider/envFallbackModel
which treats empty strings as valid overrides; change the fallback selection to
treat empty string as unset by preferring the first non-empty string. Update the
fallbackRoute construction (the object merging modelConfigRoute) to use truthy
checks (e.g., optFallbackProvider if non-empty else envFallbackProvider if
non-empty else modelConfigRoute.provider, same for model) or a small helper like
firstNonEmpty(optFallbackProvider, envFallbackProvider,
modelConfigRoute.provider) so empty "" values do not override modelConfigRoute.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ff927c6-8076-4bc8-a887-5dd03a583bac

📥 Commits

Reviewing files that changed from the base of the PR and between e6a7a07 and 539b60e.

📒 Files selected for processing (2)
  • src/lib/neurolink.ts
  • src/lib/types/streamTypes.ts

Comment thread src/lib/neurolink.ts Outdated
@Yaswanth-2874
Yaswanth-2874 force-pushed the BZ-1341-add-support-for-fallback-provider-through-feature-flag-or-env branch from 539b60e to b110118 Compare March 17, 2026 11:33
@BoraYaswanthReddy

Copy link
Copy Markdown
Contributor

me comments are outside the diff and can’t be posted inline due to platform limitations.

Fixed

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.

2 participants