Skip to content
Source
Sign inSign up
TanStack/ai

feat(ai, ai-openrouter): add defaultModelOptions to text adapters #2244

OpenHugoPerard(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2244/headopened View on GitHub

Showing 15 changed files with 91 additions and 0 deletions (loading 11).

x
0 of 15 viewed, 15 left
16 additions and 0 deletions.changeset/adapter-default-model-options.mdAdded
View file
@@ -0,0 +1,16 @@
+---
+'@tanstack/ai': minor
+'@tanstack/ai-openrouter': minor
+---
+​
+Text adapters can carry `defaultModelOptions`. `chat()` merges them under the `modelOptions` of each call, one level deep. A key that the call sets replaces the default key in full. The engine, the middleware, and the adapter all get the merged value.
+​
+`createOpenRouterText()`, `openRouterText()`, `createOpenRouterResponsesText()`, and `openRouterResponsesText()` take a `defaultModelOptions` option, for example to set provider routing for every call:
+​
+```ts
+const adapter = openRouterText('openai/gpt-5.5', {
+ defaultModelOptions: {
+ provider: { sort: 'latency', preferredMaxLatency: { p90: 2.5 } },
+ },
+})
+```
34 additions and 0 deletionsdocs/adapters/openrouter.mdModified
View file
@@ -154,6 +154,40 @@
});
```
​
+### Route every call the same way
+​
+Pass `defaultModelOptions` to the adapter. Every `chat()` call with this adapter sends them. This adapter asks OpenRouter for the provider with the lowest latency:
+​
+```typescript group=default-model-options
+import { chat } from "@tanstack/ai";
+import { openRouterText } from "@tanstack/ai-openrouter";