refactor: migrate deepinfra provider to AI SDK#11270
refactor: migrate deepinfra provider to AI SDK#11270daniel-lxs wants to merge 2 commits intomainfrom
Conversation
Migrates the DeepInfra provider from legacy RouterProvider (direct openai SDK) to AI SDK using the official @ai-sdk/deepinfra package. - Use createDeepInfra from @ai-sdk/deepinfra with streamText/generateText - Extend BaseProvider directly (like deepseek/groq pattern) - Preserve dynamic model fetching via getModels/getModelsFromCache - Pass reasoning_effort and prompt_cache_key via providerOptions - Keep custom cost calculation with calculateApiCostOpenAI - Temperature handling via getModelParams (handles o3-mini suppression) - Custom headers: X-Deepinfra-Source and X-Deepinfra-Version - isAiSdkProvider() returns true
Both issues from the previous review have been addressed. No new issues found.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
src/api/providers/deepinfra.ts
Outdated
| return createDeepInfra({ | ||
| apiKey: this.options.deepInfraApiKey ?? "not-provided", | ||
| baseURL: this.options.deepInfraBaseUrl || DEEPINFRA_DEFAULT_BASE_URL, | ||
| headers: DEEPINFRA_HEADERS, |
There was a problem hiding this comment.
The old RouterProvider-based implementation merged DEFAULT_HEADERS (HTTP-Referer, X-Title, User-Agent) with the DeepInfra-specific headers. This migration drops those standard headers. Every other AI SDK provider in the codebase (DeepSeek, Groq, Fireworks, Mistral, xAI, etc.) includes DEFAULT_HEADERS in their provider creation. Without them, DeepInfra requests no longer carry the Roo Code identification headers that other providers send.
| headers: DEEPINFRA_HEADERS, | |
| headers: { ...DEFAULT_HEADERS, ...DEEPINFRA_HEADERS }, |
You'll also need to add import { DEFAULT_HEADERS } from "./constants" to the imports.
Fix it with Roo Code or mention @roomote and request a fix.
| protected getLanguageModel(modelId: string) { | ||
| const provider = this.createProvider() | ||
| return provider(modelId) | ||
| } |
There was a problem hiding this comment.
createProvider() is called inside getLanguageModel(), which runs on every createMessage() and completePrompt() invocation. This creates a new @ai-sdk/deepinfra provider instance per API call. The DeepSeek and Groq handlers both create the provider once in the constructor and store it as this.provider. Consider caching it the same way for consistency and to avoid the repeated setup cost.
Fix it with Roo Code or mention @roomote and request a fix.
Address review feedback: - Import and include DEFAULT_HEADERS (HTTP-Referer, X-Title, User-Agent) alongside DeepInfra-specific headers, matching all other AI SDK providers. - Cache the provider instance in the constructor instead of re-creating it per request, following the DeepSeek/Groq pattern. - Add test for provider caching behavior. - Update test assertions to verify merged headers.
Migrates the DeepInfra provider from legacy RouterProvider (direct openai SDK) to AI SDK using the official
@ai-sdk/deepinfrapackage.Changes
src/api/providers/deepinfra.tsBaseProviderdirectly instead ofRouterProvider(follows the deepseek/groq pattern)createDeepInfrafrom@ai-sdk/deepinfrawithstreamText/generateTextfromaiconvertToAiSdkMessages,convertToolsForAiSdk,processAiSdkStreamPart,mapToolChoice,handleAiSdkError)Preserved Features
getModels/getModelsFromCacheintegration withfetchModel()overridereasoning_effort: Passed viaproviderOptions.deepinfraprompt_cache_key: Passed viaproviderOptions.deepinfrawhen model supports prompt cachingcalculateApiCostOpenAIwith cache token details inprocessUsageMetrics()getModelParams(o3-mini models getundefinedtemperature)max_completion_tokens: Only included whenincludeMaxTokensis trueX-Deepinfra-Source: roo-codeandX-Deepinfra-Version: 2025-08-25isAiSdkProvider(): ReturnstrueDependencies
@ai-sdk/deepinfra(^2.0.31) tosrc/package.jsonTests
src/api/providers/__tests__/deepinfra.spec.ts(21 tests, all passing)Important
Refactors DeepInfra provider to use AI SDK, updating
deepinfra.tsand tests, and adds@ai-sdk/deepinfradependency.DeepInfraHandlerindeepinfra.tsto use AI SDK, replacingRouterProviderwithBaseProvider.createDeepInfra,streamText, andgenerateTextfrom AI SDK.getModelsandgetModelsFromCache.reasoning_effort,prompt_cache_key, and custom cost calculation.max_completion_tokenslogic.X-Deepinfra-SourceandX-Deepinfra-Version.isAiSdkProvider()returnstrue.@ai-sdk/deepinfratopackage.json.deepinfra.spec.tsto cover new AI SDK-based implementation.This description was created by
for 305b26c. You can customize this summary. It will automatically update as commits are pushed.