Open History to see the last commit
1---
2title: "Community Adapters Guide"
3slug: /community-adapters/guide
4order: 1
5description: "Build and publish a community adapter for TanStack AI — package conventions, implementing the adapter interface, and publishing to npm."
6keywords:
7 - tanstack ai
8 - community adapters
9 - build adapter
10 - custom adapter
11 - provider integration
12 - adapter authoring
13 - contribute
14---
15
16This guide explains how to create and contribute community adapters for the TanStack AI ecosystem.
17
18Community adapters extend TanStack AI by integrating external services, APIs, or custom model logic. They are authored and maintained by the community and can be reused across projects.
19
20## What is a Community Adapter?
21
22A community adapter is a reusable module that connects TanStack AI to an external provider or system.
23
24Common use cases include:
25- Integrating third-party AI model providers
26- Implementing custom inference or routing logic
27- Exposing provider-specific tools or capabilities
28- Connecting to non-LLM AI services (e.g. images, embeddings, video)
29
30Community adapters are **not maintained by the core TanStack AI team**, and can be reused across different projects.
31
32## Creating a Community Adapter
33
34Follow the steps below to build a well-structured, type-safe adapter.
35
36### 1. Set up your project
37
38Start by reviewing the [existing internal adapter implementations in the TanStack AI GitHub repository](https://github.com/tanstack/ai/tree/main/packages). These define the expected structure, conventions, and integration patterns.
39
40For a complete, detailed reference, use the [OpenAI adapter](https://github.com/tanstack/ai/tree/main/packages/ai-openai), which is the most fully featured implementation.
41
42### 2. Define model metadata
43
44Model metadata describes each model’s capabilities and constraints and is used by TanStack AI for compatibility checks and feature selection.
45
46Your metadata should define, at a minimum:
47
48- Model name and identifier
49- Supported input and output modalities
50- Supported features (e.g. streaming, tools, structured output)
51- Pricing or cost information (if available)
52- Any provider-specific notes or limitations
53
54Refer to the [OpenAI adapter’s model metadata](https://github.com/TanStack/ai/blob/main/packages/ai-openai/src/model-meta.ts) for a concrete example.
55
56### 3. Define model capability arrays
57
58After defining metadata, group models by supported functionality using exported arrays. These arrays allow TanStack AI to automatically select compatible models for a given task.
59
60Example:
61```typescript ignore
62export const OPENAI_CHAT_MODELS = [
63 // Frontier models
64 GPT5_2.name,
65 GPT5_2_PRO.name,
66 GPT5_2_CHAT.name,
67 GPT5_1.name,
68 GPT5_1_CODEX.name,
69 GPT5.name,
70 GPT5_MINI.name,
71 GPT5_NANO.name,
72 GPT5_PRO.name,
73 GPT5_CODEX.name,
74 // ...other models
75] as const
76export const OPENAI_IMAGE_MODELS = [
77 GPT_IMAGE_1.name,
78 GPT_IMAGE_1_MINI.name,
79 DALL_E_3.name,
80 DALL_E_2.name,
81] as const
82
83export const OPENAI_VIDEO_MODELS = [SORA2.name, SORA2_PRO.name] as const
84```
85Each array should only include models that fully support the associated functionality.
86
87### 4. Define model provider options
88
89Each model exposes a different set of configurable options. These options must be typed per model name so that users only see valid configuration options.
90
91Example:
92```typescript ignore
93export type OpenAIChatModelProviderOptionsByName = {
94 [GPT5_2.name]: OpenAIBaseOptions &
95 OpenAIReasoningOptions &
96 OpenAIStructuredOutputOptions &
97 OpenAIToolsOptions &
98 OpenAIStreamingOptions &
99 OpenAIMetadataOptions
100 [GPT5_2_CHAT.name]: OpenAIBaseOptions &
101 OpenAIReasoningOptions &
102 OpenAIStructuredOutputOptions &
103 OpenAIToolsOptions &
104 OpenAIStreamingOptions &
105 OpenAIMetadataOptions
106 // ... repeat for each model
107}
108
109```
110This ensures strict type safety and feature correctness at compile time.
111
112### 5. Define supported input modalities
113
114Models typically support different input modalities (e.g. text, images, audio). These must be defined per model to prevent invalid usage.
115
116Example:
117```typescript ignore
118export type OpenAIModelInputModalitiesByName = {
119 [GPT5_2.name]: typeof GPT5_2.supports.input
120 [GPT5_2_PRO.name]: typeof GPT5_2_PRO.supports.input
121 [GPT5_2_CHAT.name]: typeof GPT5_2_CHAT.supports.input
122 // ... repeat for each model
123}
124```
125
126### 6. Define model option fragments
127
128Model options should be composed from reusable fragments rather than duplicated per model.
129
130A common pattern is:
131- Base options shared by all models
132- Feature fragments that are stitched together per model
133
134Example (based on [OpenAI models](https://github.com/TanStack/ai/blob/main/packages/ai-openai/src/text/text-provider-options.ts)):
135```typescript
136export interface OpenAIBaseOptions {
137 // base options that every chat model supports
138}
139
140// Feature fragments that can be stitched per-model
141
142/**
143 * Reasoning options for models
144 */
145export interface OpenAIReasoningOptions {
146 //...
147}
149/**
150 * Structured output options for models.
151 */
152export interface OpenAIStructuredOutputOptions {
153 //...
154}
155```
156
157
158Models can then opt into only the features they support:
159
160```typescript ignore
161export type OpenAIChatModelProviderOptionsByName = {
162 [GPT5_2.name]: OpenAIBaseOptions &
163 OpenAIReasoningOptions &
164 OpenAIStructuredOutputOptions &
165 OpenAIToolsOptions &
166 OpenAIStreamingOptions &
167 OpenAIMetadataOptions
168}
169```
170
171There is no single correct composition; this structure should reflect the capabilities of the provider you are integrating.
172
173### 7. Implement adapter logic
174
175Finally, implement the adapter’s runtime logic.
176
177This includes:
178- Sending requests to the external service
179- Handling streaming and non-streaming responses
180- Mapping provider responses to TanStack AI types
181- Enforcing model-specific options and constraints
182
183Adapters are implemented per capability, so only implement what your provider supports:
184
185- Text adapter
186- Chat adapter
187- Image adapter
188- Embeddings adapter
189- Video adapter
190
191Refer to the [OpenAI adapter](https://github.com/TanStack/ai/blob/main/packages/ai-openai/src/adapters/text.ts) for a complete, end-to-end implementation example.
192
193### 8. Publish and submit a PR
194
195Once your adapter is complete:
1961. Publish it as an npm package
1972. Open a PR to the [TanStack AI repository](https://github.com/TanStack/ai/pulls)
1983. Add your adapter to the [Community Adapters list in the documentation](https://github.com/TanStack/ai/tree/main/docs/community-adapters)
199
200### 9. Export a BYOK provider
201
202If users can paste an API key for your adapter, export a `defineByokProvider` object from a **`/byok` subpath** (`@scope/ai-acme/byok`). Do not re-export it from the package main entry — that pulls your provider SDK into the browser. `id` is the `x-byok-<id>` slug and is required. Set `env` to the env var **name** your adapter already reads. Names only — this object is imported on the client. Relays call `getByokKey(request, acmeByok)` from `@tanstack/ai/byok/server`.
203
204```typescript
205import { defineByokProvider } from "@tanstack/ai/byok";
206
207export const acmeByok = defineByokProvider({
208 id: "acme",
209 label: "Acme",
210 env: "ACME_API_KEY",
211});
212```
213
214Apps import `{ acmeByok } from "@scope/ai-acme/byok"` and pass it to `getByokKey(request, acmeByok)` on the relay to read the `x-byok-acme` header.
215
216### 10. Sync documentation configuration
217
218After adding your adapter, run the `pnpm run sync-docs-config` in the root of the TanStack AI monorepo. This ensures your adapter appears correctly in the documentation navigation. Open a PR with the generated changes.
219
220### 11. Maintain your adapter
221
222As a community adapter author, you are responsible for ongoing maintenance.
223
224This includes:
225
226- Tracking upstream provider API changes
227- Keeping compatibility with TanStack AI releases
228- Addressing issues and feedback from users
229- Updating documentation when features change
230
231If you add new features or breaking changes, open a follow-up PR to keep the docs in sync.