feat: add avalanche stealth provider - #1705
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add gemini-3-pro-preview and gemini-3.1-pro-preview to avalanche. Use Vertex-style URL with project/region and pass API key as query parameter instead of Bearer token. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pass token to getProviderEndpoint for avalanche provider so key= query parameter is added to the URL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WalkthroughAdds "avalanche" as a Google-compatible provider across the gateway: routing, request/response transformation, streaming, token/accounting, endpoint/header construction, model/provider definitions, and extraction tools are updated so Avalanche follows the same code paths as Obsidian/Google providers. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR adds support for the Avalanche stealth provider, a Google Vertex-compatible LLM provider with authentication and URL structure following the Vertex AI pattern. The provider offers Gemini models (3-pro-preview, 3.1-pro-preview, 3-flash-preview, and 3-pro-image-preview) with a 20% discount compared to standard pricing.
Changes:
- Added Avalanche provider configuration requiring API key, base URL, project, and optional region environment variables
- Added four Gemini model variants for Avalanche provider with tiered pricing and 20% discount
- Integrated Avalanche into all Google-style response processing logic for consistent behavior with other Google-compatible providers
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/models/src/providers.ts | Added Avalanche provider definition with Vertex-style environment configuration |
| packages/models/src/models/google.ts | Added Avalanche provider mappings for gemini-3-pro-preview, gemini-3.1-pro-preview, gemini-3-flash-preview, and gemini-3-pro-image-preview with pricing tiers and 20% discount |
| packages/actions/src/prepare-request-body.ts | Added Avalanche to Google provider case for request body transformation |
| packages/actions/src/get-provider-headers.ts | Added Avalanche to return empty headers (token passed via query parameter) |
| packages/actions/src/get-provider-endpoint.ts | Added Avalanche endpoint generation with Vertex-style URL structure including project/region/publisher path |
| apps/gateway/src/lib/logs.ts | Added Avalanche to Google provider checks for finish reason handling |
| apps/gateway/src/lib/costs.ts | Added Avalanche to Google provider group for token counting and cost calculation |
| apps/gateway/src/chat/tools/transform-streaming-to-openai.ts | Added Avalanche to Google provider case for streaming response transformation |
| apps/gateway/src/chat/tools/transform-response-to-openai.ts | Added Avalanche to Google provider case for non-streaming response transformation |
| apps/gateway/src/chat/tools/parse-provider-response.ts | Added Avalanche to Google provider case for response parsing |
| apps/gateway/src/chat/tools/extract-tool-calls.ts | Added Avalanche to Google provider case for tool call extraction |
| apps/gateway/src/chat/tools/extract-token-usage.ts | Added Avalanche to Google provider case for token usage extraction |
| apps/gateway/src/chat/tools/extract-reasoning.ts | Added Avalanche to Google provider case for reasoning content extraction |
| apps/gateway/src/chat/tools/extract-images.ts | Added Avalanche to Google provider case for image extraction |
| apps/gateway/src/chat/tools/extract-content.ts | Added Avalanche to Google provider case for content extraction |
| apps/gateway/src/chat/chat.ts | Added Avalanche to Google provider checks throughout chat handling for token passing, thought signature caching, web search counting, image counting, finish reason handling, and content filtering |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/gateway/src/chat/tools/transform-streaming-to-openai.ts (1)
254-255: Optional: fix the hardcoded"google-ai-studio"in theextractImagescall (line 431)Adding
obsidianandavalancheto this branch means line 431 now sends the wrong provider string toextractImagesfor two providers. It still works today because all four providers in this branch share the same code path inextractImages, but it's a latent correctness risk if those paths ever diverge.♻️ Suggested fix
- delta.images = extractImages(data, "google-ai-studio"); + delta.images = extractImages(data, usedProvider);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/gateway/src/chat/tools/transform-streaming-to-openai.ts` around lines 254 - 255, The switch branch that now handles case "obsidian" and case "avalanche" is calling extractImages with a hardcoded provider string "google-ai-studio"; update the call so it forwards the actual provider identifier (the variable used in the switch) instead of the hardcoded literal. Locate the cases for "obsidian"/"avalanche" and the extractImages(...) invocation in transform-streaming-to-openai (the call site referencing extractImages) and replace the static "google-ai-studio" argument with the provider variable used in the surrounding function so each provider passes its correct provider name to extractImages.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/models/src/models/google.ts`:
- Around line 767-803: The Avalanche entry for modelName
"gemini-3-flash-preview" (providerId "avalanche") has incorrect numeric
constants and an unexpected pricingTiers block: change contextSize from 1050000
to 1048576 and maxOutput from 65500 to 65535 to match sibling entries
(google-ai-studio/google-vertex), and remove the pricingTiers array entirely
unless Avalanche intentionally uses tiered pricing—if it is intentional, keep
the block but confirm the tier values are correct and documented.
---
Nitpick comments:
In `@apps/gateway/src/chat/tools/transform-streaming-to-openai.ts`:
- Around line 254-255: The switch branch that now handles case "obsidian" and
case "avalanche" is calling extractImages with a hardcoded provider string
"google-ai-studio"; update the call so it forwards the actual provider
identifier (the variable used in the switch) instead of the hardcoded literal.
Locate the cases for "obsidian"/"avalanche" and the extractImages(...)
invocation in transform-streaming-to-openai (the call site referencing
extractImages) and replace the static "google-ai-studio" argument with the
provider variable used in the surrounding function so each provider passes its
correct provider name to extractImages.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@packages/models/src/models/google.ts`:
- Around line 767-787: No change required: the model entry object for modelName
"gemini-3-flash-preview" already has corrected fields (contextSize, maxOutput,
pricing/flags) matching the google-ai-studio/vertex siblings; leave the object
(test/providerId/modelName/inputPrice/outputPrice/cachedInputPrice/requestPrice/discount/contextSize/maxOutput/reasoning/reasoningMaxTokens/streaming/vision/tools/webSearch/webSearchPrice/jsonOutput/jsonOutputSchema)
as-is and approve the change.
Add avalanche stealth provider with Vertex-style authentication and URL structure.
Includes gemini-3-pro-image-preview, gemini-3-pro-preview, gemini-3-flash-preview, and gemini-3.1-pro-preview models with 20% discount. Requires LLM_AVALANCHE_API_KEY, LLM_AVALANCHE_BASE_URL, and LLM_AVALANCHE_PROJECT environment variables. Supports optional LLM_AVALANCHE_REGION (defaults to "global").
All gateway response processing handles avalanche alongside google-ai-studio and google-vertex providers for consistent behavior.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Summary by CodeRabbit