> This page location: Functions > Templates > TanStack AI on AI Gateway
> Full Neon documentation index: https://neon.com/docs/llms.txt

# TanStack AI on AI Gateway

Streaming chat with tool calling, structured extraction, and summaries with TanStack AI on Neon AI Gateway.

- Partner: written by a company Neon works with closely
- Built by: [TanStack](https://tanstack.com/ai)
- Categories: Partner, AI

## Install

```bash
neon functions new tanstack-ai
```

## What this function exposes

After you deploy, call these paths on the function URL.

### Stream a chat (recommended)

POST the AG-UI body that useChat sends to stream a reply over SSE, with a sample server tool.

- Route: `/chat`
- Install only this operation: `neon functions new tanstack-ai --operation chat`

### Extract structured data (recommended)

POST text to get a typed JSON object validated against a Zod schema.

- Route: `/extract`
- Install only this operation: `neon functions new tanstack-ai --operation extract`

### Summarize text

POST text and an optional style and maxLength to get a summary.

- Route: `/summarize`
- Install only this operation: `neon functions new tanstack-ai --operation summarize`

## Environment variables

The CLI declares these variables in `neon.ts` and adds them to `.env.example` without values, so you need to fill in the required ones before you run the function.

| Variable | Description | Required |
| --- | --- | --- |
| `TANSTACK_AI_FUNCTION_TOKEN` | Random token (at least 32 characters, for example from openssl rand -hex 32) callers send as Authorization: Bearer \<token\>; required because Neon Function URLs are public. | Yes |

## Run it

Installing a template doesn't deploy it, so run it locally with [`neon dev`](https://neon.com/docs/cli/dev.md) first, and deploy it to a branch with [`neon deploy`](https://neon.com/docs/compute/functions/deploy.md) once it works.

## Related

- Previous: [Authenticated API with Hono and Managed Better Auth](https://neon.com/functions/templates/authenticated-api.md)
- Next: [Live poll over WebSockets](https://neon.com/functions/templates/websocket-live-poll.md)
- [All templates](https://neon.com/functions/templates.md)
- [Template source](https://github.com/neondatabase/examples/tree/main/registry/tanstack-ai)
- [Use function templates](https://neon.com/docs/compute/functions/templates.md)
- [Contribute a function template](https://neon.com/docs/compute/functions/registry.md)

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/functions/templates/tanstack-ai"}` to https://feedback.neon.tech/ (no auth required).