Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8583c9a
Update openrouter package, models, and scripts to generate openrouter…
tombeckenham Feb 23, 2026
2bbda65
ci: apply automated fixes
autofix-ci[bot] Feb 23, 2026
6f8873b
Added compare script and fixed key name issue in fetch models
tombeckenham Feb 23, 2026
50ec22e
resolved coderabbit issues
tombeckenham Feb 23, 2026
cde3155
ci: apply automated fixes
autofix-ci[bot] Feb 23, 2026
70f0bcf
Added support for openrouter structured output
tombeckenham Feb 24, 2026
8acf2a4
Address PR #312 review feedback: improve error handling and cleanup
tombeckenham Feb 24, 2026
348d363
Merge branch 'main' into pr/tombeckenham/312
tombeckenham Mar 3, 2026
761380a
Update model metadata and pricing in OpenRouter, add new models, and …
tombeckenham Mar 4, 2026
823747b
ci: apply automated fixes
autofix-ci[bot] Mar 4, 2026
6467f59
Update openrouter package models and added prettier to fetch script
tombeckenham Mar 4, 2026
f60bd3b
Updated models and script
tombeckenham Mar 4, 2026
c498acc
ci: apply automated fixes
autofix-ci[bot] Mar 4, 2026
6ebe8b1
Update openrouter package to 0.9.11
tombeckenham Mar 4, 2026
340cb82
Refactor OpenRouter options passthrough and bump fal client
tombeckenham Mar 4, 2026
c7ce94b
Refactor text-provider-options to derive types from SDK's ChatGenerat…
tombeckenham Mar 4, 2026
655e5fe
ci: apply automated fixes
autofix-ci[bot] Mar 4, 2026
ed027a1
Changeset updated
tombeckenham Mar 4, 2026
42e73fb
Merge remote-tracking branch 'upstream/main' into tombeckenham/issue310
tombeckenham Mar 9, 2026
50c4617
Merge remote-tracking branch 'upstream/main' into pr/tombeckenham/312
tombeckenham Mar 12, 2026
5e27d94
Merge remote-tracking branch 'upstream/main' into tombeckenham/issue310
tombeckenham Mar 13, 2026
13ed768
Merge remote-tracking branch 'upstream/main' into tombeckenham/issue310
tombeckenham Apr 17, 2026
4ebc7d2
ci: apply automated fixes
autofix-ci[bot] Apr 17, 2026
6e16c0e
chore(ai-openrouter): upgrade @openrouter/sdk to 0.12.13
tombeckenham Apr 17, 2026
a45e2fb
ci: apply automated fixes
autofix-ci[bot] Apr 17, 2026
45d216f
chore(ai-openrouter): expand changeset, wire format into generate:models
tombeckenham Apr 17, 2026
d21f546
Corrected openrouter params in example
tombeckenham Apr 17, 2026
b094d8b
chore(ai-openrouter): bump @openrouter/sdk to 0.12.14
tombeckenham Apr 17, 2026
9593342
chore(ai-openrouter): clarify changeset, tidy image error check, docu…
tombeckenham Apr 17, 2026
d00d811
docs(ai-openrouter): explain modelOptions-first spread ordering in te…
tombeckenham Apr 17, 2026
09962f7
fix(ai-openrouter): apply OpenAI-strict transformation to structuredO…
tombeckenham Apr 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/giant-garlics-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tanstack/ai-openrouter': patch
---

- Updated openrouter sdk to 0.8.0
- Updated model list to include Opus 4.6, Sonnet 4.6, and Gemini 3.1 Pro amongst others
- Updated structured output support to natively support open router structured output
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"dev": "pnpm run watch",
"format": "prettier --experimental-cli --ignore-unknown '**/*' --write",
"generate-docs": "node scripts/generate-docs.ts && pnpm run copy:readme",
"fetch:models": "tsx scripts/fetch-openrouter-models.ts",
"generate:models": "tsx scripts/convert-openrouter-models.ts",
"sync-docs-config": "node scripts/sync-docs-config.ts",
"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",
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/ai-openrouter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"adapter"
],
"dependencies": {
"@openrouter/sdk": "0.3.15",
"@openrouter/sdk": "0.8.0",
"@tanstack/ai": "workspace:*"
},
"devDependencies": {
Expand Down
44 changes: 23 additions & 21 deletions packages/typescript/ai-openrouter/src/adapters/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,30 @@ export class OpenRouterImageAdapter<

try {
const response = await this.client.chat.send({
model,
messages: [
{
role: 'user',
content: prompt,
chatGenerationParams: {
model,
messages: [
{
role: 'user',
content: prompt,
},
],
modalities: ['image'],
stream: false,
// OpenRouter filters out invalid config per provider specifications
imageConfig: {
...(numberOfImages ? { n: numberOfImages, numberOfImages } : {}),
...(aspectRatio
? {
aspect_ratio: aspectRatio,
}
: {}),
...(modelOptions?.image_size
? {
image_size: modelOptions.image_size,
}
: {}),
},
],
modalities: ['image'],
stream: false,
// OpenRouter filters out invalid config per provider specifications
imageConfig: {
...(numberOfImages ? { n: numberOfImages, numberOfImages } : {}),
...(aspectRatio
? {
aspect_ratio: aspectRatio,
}
: {}),
...(modelOptions?.image_size
? {
image_size: modelOptions.image_size,
}
: {}),
},
})

Expand Down
64 changes: 21 additions & 43 deletions packages/typescript/ai-openrouter/src/adapters/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class OpenRouterTextAdapter<
try {
const requestParams = this.mapTextOptionsToSDK(options)
const stream = await this.client.chat.send(
{ ...requestParams, stream: true },
{ chatGenerationParams: { ...requestParams, stream: true } },
{ signal: options.request?.signal },
)
Comment thread
tombeckenham marked this conversation as resolved.

Expand Down Expand Up @@ -218,59 +218,37 @@ export class OpenRouterTextAdapter<

const requestParams = this.mapTextOptionsToSDK(chatOptions)

const structuredOutputTool = {
type: 'function' as const,
function: {
name: 'structured_output',
description:
'Use this tool to provide your response in the required structured format.',
parameters: outputSchema,
},
}

try {
const result = await this.client.chat.send(
{
...requestParams,
stream: false,
tools: [structuredOutputTool],
toolChoice: {
type: 'function',
function: { name: 'structured_output' },
chatGenerationParams: {
...requestParams,
stream: false,
responseFormat: {
type: 'json_schema',
jsonSchema: {
name: 'structured_output',
schema: outputSchema,
strict: true,
},
},
},
},
{ signal: chatOptions.request?.signal },
)

const message = result.choices[0]?.message
const toolCall = message?.toolCalls?.[0]

if (toolCall && toolCall.function.name === 'structured_output') {
const parsed = JSON.parse(toolCall.function.arguments || '{}')
return {
data: parsed,
rawText: toolCall.function.arguments || '',
}
}

const content = (message?.content as any) || ''
let parsed: unknown
try {
parsed = JSON.parse(content)
} catch {
throw new Error(
`Failed to parse structured output as JSON. Content: ${content.slice(0, 200)}${content.length > 200 ? '...' : ''}`,
)
}

return {
data: parsed,
rawText: content,
}
const content = result.choices[0]?.message.content
const rawText = typeof content === 'string' ? content : ''
const parsed = JSON.parse(rawText)
return { data: parsed, rawText }
Comment thread
tombeckenham marked this conversation as resolved.
} catch (error: unknown) {
if (error instanceof RequestAbortedError) {
throw new Error('Structured output generation aborted')
}
if (error instanceof SyntaxError) {
throw new Error(
`Failed to parse structured output as JSON: ${error.message}`,
)
}
const err = error as Error
throw new Error(
`Structured output generation failed: ${err.message || 'Unknown error occurred'}`,
Expand Down
Loading
Loading