MCPcopy Create free account
hub / github.com/TanStack/ai / adapterFor

Function adapterFor

examples/ts-react-chat/src/routes/api.structured-output.ts:137–186  ·  view source on GitHub ↗
(provider: Provider, model?: string)

Source from the content-addressed store, hash-verified

135}
136
137function adapterFor(provider: Provider, model?: string): AnyTextAdapter {
138 const baseModel = stripModelSuffix(model)
139 switch (provider) {
140 case 'openai':
141 return openaiText((baseModel || 'gpt-5.2') as 'gpt-5.2')
142 case 'openai-chat':
143 // Same model surface as the Responses adapter, but talks to
144 // `/v1/chat/completions`. Useful for side-by-side comparison of
145 // streaming structured output across the two OpenAI wire formats.
146 return openaiChatCompletions((baseModel || 'gpt-4o') as 'gpt-4o')
147 case 'anthropic':
148 // Claude 4.5+ supports native combined tools + schema-constrained
149 // streaming (#605) via `output_config.format` on the beta Messages
150 // endpoint. Earlier models fall back to the forced-tool-use
151 // workaround in `structuredOutput` (no real streaming).
152 return anthropicText(
153 (baseModel || 'claude-sonnet-4-5') as 'claude-sonnet-4-5',
154 )
155 case 'gemini':
156 // Gemini 3.x supports native combined tools + schema-constrained
157 // streaming (#605) via `config.responseSchema` +
158 // `responseMimeType: 'application/json'` on a single
159 // `generateContentStream` call. Gemini 2.x is documented as brittle
160 // for the combination and falls back to the engine's legacy
161 // finalization path.
162 //
163 // Default is `gemini-3.5-flash`: the newest *stable* (non-preview)
164 // 3.x id, matching the dropdown's first entry. The previous default
165 // (`gemini-3-pro-preview`) was retired by Google and now 404s.
166 return geminiText((baseModel || 'gemini-3.5-flash') as 'gemini-3.5-flash')
167 case 'grok':
168 return grokText((model || 'grok-build-0.1') as 'grok-build-0.1')
169 case 'groq':
170 return groqText(
171 (model ||
172 'meta-llama/llama-4-maverick-17b-128e-instruct') as 'meta-llama/llama-4-maverick-17b-128e-instruct',
173 )
174 case 'openrouter':
175 return openRouterText(
176 (model || 'anthropic/claude-opus-4.6') as 'anthropic/claude-opus-4.6',
177 )
178 case 'openrouter-responses':
179 // OpenRouter Responses (beta) endpoint — same model surface as the
180 // chat-completions adapter, but routes through `/v1/responses`. This
181 // is what exercises `OpenRouterResponsesTextAdapter.structuredOutputStream`.
182 return openRouterResponsesText(
183 (model || 'anthropic/claude-opus-4.6') as 'anthropic/claude-opus-4.6',
184 )
185 }
186}
187
188// Per-provider modelOptions to opt into reasoning surfacing. Without these,
189// reasoning models reason silently and the UI never sees REASONING_* events.

Callers 1

Calls 9

openaiTextFunction · 0.90
openaiChatCompletionsFunction · 0.90
anthropicTextFunction · 0.90
geminiTextFunction · 0.90
grokTextFunction · 0.90
groqTextFunction · 0.90
openRouterTextFunction · 0.90
openRouterResponsesTextFunction · 0.90
stripModelSuffixFunction · 0.85

Tested by

no test coverage detected