ai-core/adapter-configuration
Adapter Configuration provides structured patterns for initializing AI provider adapters (OpenAI, Anthropic, Gemini, Grok) with TanStack AI's `chat()` function. Use this skill when setting up language model connections, selecting specific model versions, configuring sampling parameters like temperature and token limits, and handling provider-specific authentication and API configuration across different LLM providers.
git clone --depth 1 https://github.com/TanStack/ai /tmp/ai-core-adapter-configuration && cp -r /tmp/ai-core-adapter-configuration/packages/ai/skills/ai-core/adapter-configuration ~/.claude/skills/ai-core-adapter-configurationSKILL.md
# Adapter Configuration
> **Dependency:** This skill builds on ai-core. Read it first for critical rules.
> **Before implementing:** Ask the user which provider and model they want.
> Then fetch the latest available models from the provider's source code
> (check the adapter's model metadata file, e.g. `packages/ai-openai/src/model-meta.ts`)
> or from the provider's API/docs to recommend the most current model.
> The model lists in this skill and its reference files may be outdated.
> Always verify against the source before recommending a specific model.
## Setup
Create an adapter and use it with `chat()`:
```typescript
import { chat, toServerSentEventsResponse } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
const stream = chat({
adapter: openaiText('gpt-5.2'),
messages,
modelOptions: {
temperature: 0.7,
max_output_tokens: 1000,
},
})
return toServerSentEventsResponse(stream)
```
The adapter factory function takes the model name as a string literal and an
optional config object (API key, base URL, etc.). The model name is passed
into the factory, not into `chat()`.
Sampling options (`temperature`, token limits, `top_p`/`topP`, etc.) live
inside `modelOptions` using each provider's native key — they are **not**
top-level options on `chat()`. See the per-provider table in
[Configuring Sampling](#5-configuring-sampling) below.
## Core Patterns
### 1. Adapter Selection
Each provider has a dedicated package with tree-shakeable adapter factories.
The text adapter is the primary one for chat/completions:
| Provider | Package | Factory | Env Var |
| ----------------- | -------------------------------- | ------------------------------------------- | ------------------------------------------------- |
| OpenAI | `@tanstack/ai-openai` | `openaiText` | `OPENAI_API_KEY` |
| Anthropic | `@tanstack/ai-anthropic` | `anthropicText` | `ANTHROPIC_API_KEY` |
| Gemini | `@tanstack/ai-gemini` | `geminiText` | `GOOGLE_API_KEY` or `GEMINI_API_KEY` |
| Grok (xAI) | `@tanstack/ai-grok` | `grokText` | `XAI_API_KEY` |
| Groq | `@tanstack/ai-groq` | `groqText` | `GROQ_API_KEY` |
| OpenRouter | `@tanstack/ai-openrouter` | `openRouterText` | `OPENROUTER_API_KEY` |
| Ollama | `@tanstack/ai-ollama` | `ollamaText` | `OLLAMA_HOST` (default: `http://localhost:11434`) |
| OpenAI-compatible | `@tanstack/ai-openai/compatible` | `openaiCompatible` / `openaiCompatibleText` | provider-specific (passed via `apiKey`) |
```typescript
// Each factory takes model as first arg, optional config as second
import { openaiText } from '@tanstack/ai-openai'
import { anthropicText } from '@tanstack/ai-anthropic'
import { geminiText } from '@tanstack/ai-gemini'
import { grokText } from '@tanstack/ai-grok'
import { groqText } from '@tanstack/ai-groq'
import { openRouterText } from '@tanstack/ai-openrouter'
import { ollamaText } from '@tanstack/ai-ollama'
// Model string is passed to the factory, NOT to chat()
const adapter = openaiText('gpt-5.2')
const adapter2 = anthropicText('claude-sonnet-4-6')
const adapter3 = geminiText('gemini-2.5-pro')
const adapter4 = grokText('grok-4')
const adapter5 = groqText('llama-3.3-70b-versatile')
const adapter6 = openRouterText('anthropic/claude-sonnet-4')
const adapter7 = ollamaText('llama3.3')
// Optional: pass explicit API key
const adapterWithKey = openaiText('gpt-5.2', {
apiKey: 'sk-...',
})
```
### 2. Runtime Adapter Switching
Use an adapter factory map to switch providers dynamically based on user
input or configuration:
```typescript
import { chat, toServerSentEventsResponse } from '@tanstack/ai'
import type { TextAdapter } from '@tanstack/ai/adapters'
import { openaiText } from '@tanstack/ai-openai'
import { anthropicText } from '@tanstack/ai-anthropic'
import { geminiText } from '@tanstack/ai-gemini'
// Define a map of provider+model to adapter factory calls
const adapters: Record<string, () => TextAdapter> = {
'openai/gpt-5.2': () => openaiText('gpt-5.2'),
'anthropic/claude-sonnet-4-6': () => anthropicText('claude-sonnet-4-6'),
'gemini/gemini-2.5-pro': () => geminiText('gemini-2.5-pro'),
}
export function handleChat(providerModel: string, messages: Array<any>) {
const createAdapter = adapters[providerModel]
if (!createAdapter) {
throw new Error(`Unknown provider/model: ${providerModel}`)
}
const stream = chat({
adapter: createAdapter(),
messages,
})
return toServerSentEventsResponse(stream)
}
```
### 3. Configuring Reasoning / Thinking
Different providers expose reasoning/thinking through their `modelOptions`:
```typescript
import { chat } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
import { anthropicText } from '@tanstack/ai-anthropic'
import { geminiText } from '@tanstack/ai-gemini'
// OpenAI: reasoning with effort and summary
const openaiStream = chat({
adapter: openaiText('gpt-5.2'),
messages,
modelOptions: {
reasoning: {
effort: 'high',
summary: 'auto',
},
},
})
// Anthropic: extended thinking with budget_tokens
const anthropicStream = chat({
adapter: anthropicText('claude-sonnet-4-6'),
messages,
modelOptions: {
max_tokens: 16000,
thinking: {
type: 'enabled',
budget_tokens: 8000, // must be >= 1024 and < max_tokens
},
},
})
// Anthropic: adaptive thinking (claude-sonnet->
Triage all open GitHub issues, PRs, and discussions in the current repository by fanning out up to 100 parallel subagents (one per item), then produce a single prioritized report ranking which PRs to review first, which issues to address first, and which discussions need maintainer attention. Use when the user asks to "triage open issues/PRs", "triage discussions", "prioritize the backlog", "what should I review first", "sweep the repo", or any request to bulk-evaluate open GitHub work and recommend an order.
>
>
>
>
>
>