Skip to content

Commit 6e16c0e

Browse files
tombeckenhamclaude
andcommitted
chore(ai-openrouter): upgrade @openrouter/sdk to 0.12.13
The SDK renamed every chat-related exported type (ChatGenerationParams → ChatRequest, ChatResponse → ChatResult, etc.) and renamed the request wrapper key on chat.send from chatGenerationParams to chatRequest. Migrate adapters and tests to the new names. The SDK also narrowed ChatRequest to OpenAI-compatible fields, so Zod strips topK/topA/minP/repetitionPenalty/includeReasoning/verbosity/ webSearchOptions from outbound requests. Drop these keys from OpenRouterBaseOptions and the model catalog so callers get a TS error instead of silent no-op behavior, and add them to excludedParams in the catalog generator so future syncs stay honest. Also restore the SDK-derived shape of text-provider-options that was lost to an upstream merge, re-keyed off ChatRequest. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4ebc7d2 commit 6e16c0e

9 files changed

Lines changed: 8664 additions & 17110 deletions

File tree

packages/typescript/ai-openrouter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"adapter"
4040
],
4141
"dependencies": {
42-
"@openrouter/sdk": "0.9.11",
42+
"@openrouter/sdk": "0.12.13",
4343
"@tanstack/ai": "workspace:*"
4444
},
4545
"devDependencies": {

packages/typescript/ai-openrouter/src/adapters/image.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
ImageGenerationResult,
1818
} from '@tanstack/ai'
1919
import type { OPENROUTER_IMAGE_MODELS } from '../model-meta'
20-
import type { ChatResponse } from '@openrouter/sdk/models'
20+
import type { ChatResult } from '@openrouter/sdk/models'
2121

2222
export interface OpenRouterImageConfig extends OpenRouterClientConfig {}
2323

@@ -71,7 +71,7 @@ export class OpenRouterImageAdapter<
7171

7272
try {
7373
const response = await this.client.chat.send({
74-
chatGenerationParams: {
74+
chatRequest: {
7575
model,
7676
messages: [
7777
{
@@ -98,12 +98,12 @@ export class OpenRouterImageAdapter<
9898
},
9999
})
100100

101-
// Check for error in response
102-
if ('error' in response && response.error) {
101+
const maybeError = (response as { error?: unknown }).error
102+
if (maybeError) {
103103
const errorMsg =
104-
typeof response.error === 'object' && 'message' in response.error
105-
? (response.error as { message: string }).message
106-
: String(response.error)
104+
typeof maybeError === 'object' && 'message' in maybeError
105+
? String((maybeError as { message: unknown }).message)
106+
: String(maybeError)
107107
throw new Error(`Image generation failed: ${errorMsg}`)
108108
}
109109

@@ -120,7 +120,7 @@ export class OpenRouterImageAdapter<
120120

121121
private transformResponse(
122122
model: string,
123-
response: ChatResponse,
123+
response: ChatResult,
124124
): ImageGenerationResult {
125125
const images: Array<GeneratedImage> = []
126126

packages/typescript/ai-openrouter/src/adapters/text.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import type {
2828
OpenRouterMessageMetadataByModality,
2929
} from '../message-types'
3030
import type {
31-
ChatGenerationParams,
32-
ChatGenerationTokenUsage,
33-
ChatMessageContentItem,
34-
ChatStreamingChoice,
35-
Message,
31+
ChatContentItems,
32+
ChatMessages,
33+
ChatRequest,
34+
ChatStreamChoice,
35+
ChatUsage,
3636
} from '@openrouter/sdk/models'
3737

3838
export interface OpenRouterConfig extends SDKOptions {}
@@ -108,7 +108,7 @@ export class OpenRouterTextAdapter<
108108
try {
109109
const requestParams = this.mapTextOptionsToSDK(options)
110110
const stream = await this.client.chat.send(
111-
{ chatGenerationParams: { ...requestParams, stream: true } },
111+
{ chatRequest: { ...requestParams, stream: true } },
112112
{ signal: options.request?.signal },
113113
)
114114

@@ -211,7 +211,7 @@ export class OpenRouterTextAdapter<
211211
try {
212212
const result = await this.client.chat.send(
213213
{
214-
chatGenerationParams: {
214+
chatRequest: {
215215
...requestParams,
216216
stream: false,
217217
responseFormat: {
@@ -254,12 +254,12 @@ export class OpenRouterTextAdapter<
254254
}
255255

256256
private *processChoice(
257-
choice: ChatStreamingChoice,
257+
choice: ChatStreamChoice,
258258
toolCallBuffers: Map<number, ToolCallBuffer>,
259259
meta: { id: string; model: string; timestamp: number },
260260
accumulated: { reasoning: string; content: string },
261261
updateAccumulated: (reasoning: string, content: string) => void,
262-
usage: ChatGenerationTokenUsage | undefined,
262+
usage: ChatUsage | undefined,
263263
aguiState: AGUIState,
264264
): Iterable<StreamChunk> {
265265
const delta = choice.delta
@@ -479,7 +479,7 @@ export class OpenRouterTextAdapter<
479479

480480
private mapTextOptionsToSDK(
481481
options: TextOptions<ResolveProviderOptions<TModel>>,
482-
): ChatGenerationParams {
482+
): ChatRequest {
483483
const modelOptions = options.modelOptions
484484

485485
const messages = this.convertMessages(options.messages)
@@ -491,7 +491,7 @@ export class OpenRouterTextAdapter<
491491
})
492492
}
493493

494-
const request: ChatGenerationParams = {
494+
const request: ChatRequest = {
495495
...modelOptions,
496496
model:
497497
options.model +
@@ -512,7 +512,7 @@ export class OpenRouterTextAdapter<
512512
return request
513513
}
514514

515-
private convertMessages(messages: Array<ModelMessage>): Array<Message> {
515+
private convertMessages(messages: Array<ModelMessage>): Array<ChatMessages> {
516516
return messages.map((msg) => {
517517
if (msg.role === 'tool') {
518518
return {
@@ -552,11 +552,11 @@ export class OpenRouterTextAdapter<
552552

553553
private convertContentParts(
554554
content: string | null | Array<ContentPart>,
555-
): Array<ChatMessageContentItem> {
555+
): Array<ChatContentItems> {
556556
if (!content) return [{ type: 'text', text: '' }]
557557
if (typeof content === 'string') return [{ type: 'text', text: content }]
558558

559-
const parts: Array<ChatMessageContentItem> = []
559+
const parts: Array<ChatContentItems> = []
560560
for (const part of content) {
561561
switch (part.type) {
562562
case 'text':

0 commit comments

Comments
 (0)