Skip to content

Commit 8583c9a

Browse files
committed
Update openrouter package, models, and scripts to generate openrouter models
Fixes #310
1 parent 1f800aa commit 8583c9a

12 files changed

Lines changed: 15849 additions & 25917 deletions

File tree

.changeset/giant-garlics-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/ai-openrouter': patch
3+
---
4+
5+
Updated sdk to 0.8.0 and model list

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"dev": "pnpm run watch",
3434
"format": "prettier --experimental-cli --ignore-unknown '**/*' --write",
3535
"generate-docs": "node scripts/generate-docs.ts && pnpm run copy:readme",
36+
"fetch:models": "tsx scripts/fetch-openrouter-models.ts",
3637
"generate:models": "tsx scripts/convert-openrouter-models.ts",
3738
"sync-docs-config": "node scripts/sync-docs-config.ts",
3839
"copy:readme": "cp README.md packages/typescript/ai/README.md && cp README.md packages/typescript/ai-devtools/README.md && cp README.md packages/typescript/preact-ai-devtools/README.md && cp README.md packages/typescript/ai-client/README.md && cp README.md packages/typescript/ai-gemini/README.md && cp README.md packages/typescript/ai-ollama/README.md && cp README.md packages/typescript/ai-openai/README.md && cp README.md packages/typescript/ai-react/README.md && cp README.md packages/typescript/ai-react-ui/README.md && cp README.md packages/typescript/react-ai-devtools/README.md && cp README.md packages/typescript/solid-ai-devtools/README.md",
@@ -72,4 +73,4 @@
7273
"vite": "^7.2.7",
7374
"vitest": "^4.0.14"
7475
}
75-
}
76+
}

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.3.15",
42+
"@openrouter/sdk": "0.8.0",
4343
"@tanstack/ai": "workspace:*"
4444
},
4545
"devDependencies": {

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,30 @@ export class OpenRouterImageAdapter<
7171

7272
try {
7373
const response = await this.client.chat.send({
74-
model,
75-
messages: [
76-
{
77-
role: 'user',
78-
content: prompt,
74+
chatGenerationParams: {
75+
model,
76+
messages: [
77+
{
78+
role: 'user',
79+
content: prompt,
80+
},
81+
],
82+
modalities: ['image'],
83+
stream: false,
84+
// OpenRouter filters out invalid config per provider specifications
85+
imageConfig: {
86+
...(numberOfImages ? { n: numberOfImages, numberOfImages } : {}),
87+
...(aspectRatio
88+
? {
89+
aspect_ratio: aspectRatio,
90+
}
91+
: {}),
92+
...(modelOptions?.image_size
93+
? {
94+
image_size: modelOptions.image_size,
95+
}
96+
: {}),
7997
},
80-
],
81-
modalities: ['image'],
82-
stream: false,
83-
// OpenRouter filters out invalid config per provider specifications
84-
imageConfig: {
85-
...(numberOfImages ? { n: numberOfImages, numberOfImages } : {}),
86-
...(aspectRatio
87-
? {
88-
aspect_ratio: aspectRatio,
89-
}
90-
: {}),
91-
...(modelOptions?.image_size
92-
? {
93-
image_size: modelOptions.image_size,
94-
}
95-
: {}),
9698
},
9799
})
98100

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class OpenRouterTextAdapter<
114114
try {
115115
const requestParams = this.mapTextOptionsToSDK(options)
116116
const stream = await this.client.chat.send(
117-
{ ...requestParams, stream: true },
117+
{ chatGenerationParams: { ...requestParams, stream: true } },
118118
{ signal: options.request?.signal },
119119
)
120120

@@ -231,12 +231,14 @@ export class OpenRouterTextAdapter<
231231
try {
232232
const result = await this.client.chat.send(
233233
{
234-
...requestParams,
235-
stream: false,
236-
tools: [structuredOutputTool],
237-
toolChoice: {
238-
type: 'function',
239-
function: { name: 'structured_output' },
234+
chatGenerationParams: {
235+
...requestParams,
236+
stream: false,
237+
tools: [structuredOutputTool],
238+
toolChoice: {
239+
type: 'function',
240+
function: { name: 'structured_output' },
241+
},
240242
},
241243
},
242244
{ signal: chatOptions.request?.signal },

0 commit comments

Comments
 (0)