> ## Documentation Index
> Fetch the complete documentation index at: https://docs.supa.works/llms.txt
> Use this file to discover all available pages before exploring further.

# TanStack AI

> Use TanStack AI's OpenAI adapter with SUPA.

Use [TanStack AI](https://tanstack.com/ai/latest) with the [`@tanstack/ai-openai`](https://tanstack.com/ai/latest/docs/adapters/openai) adapter and SUPA's OpenAI-compatible API.

TanStack's OpenAI adapter builds on the official `openai` package. Set `baseURL` to SUPA and pass your SUPA model id (for example `google/gemma-3-27b-it`).

<Warning>
  TanStack AI currently types chat model names as OpenAI model ids. Use a type assertion for custom SUPA model strings until your project exposes them in typings. The runtime request still sends your SUPA model name to the API.
</Warning>

## Prerequisites

* A SUPA API key from your [profile page](https://app.supa.works/user)
* Node.js 18+ (TanStack AI recommends current Node LTS; see their docs for any stricter requirement)

## Install

```bash theme={null}
npm install @tanstack/ai @tanstack/ai-openai zod
```

## Configure the adapter

Use [`createOpenaiChat`](https://github.com/TanStack/ai/blob/main/packages/typescript/ai-openai/src/adapters/text.ts) with `apiKey`, `baseURL`, and your model id.

```typescript theme={null}
import { createOpenaiChat } from '@tanstack/ai-openai';
import type { OpenAIChatModel } from '@tanstack/ai-openai';

const adapter = createOpenaiChat(
  'google/gemma-3-27b-it' as OpenAIChatModel,
  process.env.SUPA_API_KEY!,
  { baseURL: 'https://api.supa.works/openai/v1' },
);
```

## Chat (non-streaming)

The TanStack [`chat`](https://tanstack.com/ai/latest/docs) activity accepts your adapter and messages. Set `stream: false` to collect the full reply as a string.

```typescript theme={null}
import { chat } from '@tanstack/ai';

const text = await chat({
  adapter,
  stream: false,
  messages: [
    {
      role: 'user',
      content: [{ type: 'text', content: 'What is a banana?' }],
    },
  ],
});

console.log(text);
```

## Streaming

Omit `stream` or set `stream: true` to receive an async iterable of stream chunks (see TanStack AI docs for consuming chunks).

## Next steps

* [Tool calls with TanStack AI](/examples/tool-calls#tanstack-ai) shows `toolDefinition` and `.server()` with SUPA.
* [Image attachments with TanStack AI](/examples/image-attachments#tanstack-ai) shows multimodal `content` parts.
* [Vercel AI SDK](/guides/vercel-ai-sdk) if you prefer `@ai-sdk/openai` and `generateText` / `streamText`.
