{"slug": "save-tokens-with-neon-function-templates", "title": "Save tokens with Neon Function templates", "summary": "Neon launched the Neon Function Registry, a collection of ready-made Node.js function templates that developers and AI agents can add to a Neon project with a single command, the company said. The registry includes templates built with Vercel's Chat SDK, Mastra, Context.dev and WorkOS, plus templates for Postgres, the Neon AI Gateway, Neon Object Storage and Managed Better Auth, and agents can list and install them via `neon functions templates list` and `neon functions new <id> -y` without a linked project or signed-in CLI. Neon positions the templates as a token and time saver, since agents otherwise spend tokens reading docs and picking package versions before writing code; deploying requires Neon CLI 8.11.0 or later and a directory linked to a Neon project.", "body_md": "A few weeks ago we launched [Neon Functions](https://neon.com/blog/neon-functions-backend-logic-next-to-your-data), Node.js functions that run in your Neon project in the same region as your Postgres database, with enough runtime for agents that stream for minutes or WebSockets that stay open.\n\nToday we're introducing the [Neon Function Registry](https://neon.com/functions/templates), a collection of ready-made functions you add to a project with one command.\n\nAgents can already bootstrap a function on their own, but before they write any code they read the docs, look up best practices, figure out [`neon.ts`](https://neon.com/docs/reference/neon-ts) and pick package versions. All of that costs tokens and time.\n\nWith the registry, your agent starts from a working template and spends its time on something more useful like building your app.\n\n## Templates worth trying\n\nHere is a small collection of some of my favorite templates, built with [Vercel's Chat SDK](https://chat-sdk.dev/), [Mastra](https://mastra.ai/), [Context.dev](https://www.context.dev/) and [WorkOS](https://workos.com/):\n\n- [First Party](https://neon.com/functions/templates/chat-sdk)### Chat SDK bot for Slack, Telegram, and the webA Vercel Chat SDK bot that answers on Slack, Telegram, and useChat, streams replies from AI Gateway, and keeps conversations, subscriptions, and locks in Neon Postgres.\n### Mastra agent with Postgres memoryA Mastra agent that remembers users in Neon Postgres, streams chat for useChat on AI Gateway, and runs a resumable human-in-the-loop review workflow.\n### Context.dev web dataSearch the web and news, read pages, answer questions, and retrieve brand data with Context.dev.\n### Mirror WorkOS data into PostgresBackfill, tail the Events API, and reconcile drift on a cron, with a WorkOS webhook nudge. Join users, organizations, and memberships in SQL.\n\nThe rest of the collection uses the Neon services you may already use for your project:\n\n- **Postgres**[`rest-api-postgres`](https://neon.com/functions/templates/rest-api-postgres) and[` mcp-postgres`](https://neon.com/functions/templates/mcp-postgres) read and write your database through the`DATABASE_URL` Neon injects.\n- **AI Gateway**[`openai-agents`](https://neon.com/functions/templates/openai-agents) runs a streaming[OpenAI Agents SDK](https://openai.github.io/openai-agents-js/) agent with tools and handoffs on models from the[Neon AI Gateway](https://neon.com/docs/ai-gateway/overview) .\n- **Object Storage**[`image-generation`](https://neon.com/functions/templates/image-generation) creates an image with the AI Gateway and stores it in[Neon Object Storage](https://neon.com/docs/storage/overview) .\n- **Auth**[`authenticated-api`](https://neon.com/functions/templates/authenticated-api) checks callers with[Managed Better Auth](https://neon.com/docs/auth/overview) .\n\nBecause those services live in the same project as the function, you don't need to sign up for a separate database, storage provider or AI Gateway to use a template.\n\n## Why templates work so well for agents\n\nA template hands an agent pre-built code it would otherwise have to write itself, in a form it can install without stopping to ask you questions:\n\n- `neon functions templates list` returns every available template's ID, so the agent can pick one without browsing the website.\n- `neon functions new <id> -y` installs the recommended setup and the pinned dependency versions without any prompts.\n- `neon functions new` doesn't need a linked project or a signed-in CLI, so an agent can add a template before anyone has logged in.\n\nEach template comes with a README that lists the services it needs and how to make an example request, so the agent knows how to call the function once it's running.\n\n## How to get going\n\nThis section walks through adding a template, from the first command to a deployed function. You need [Neon CLI](https://neon.com/docs/cli/install) 8.11.0 or later and a directory [linked](https://neon.com/docs/cli/link) to a Neon project to deploy:\n\nAfter that, a template usually needs a few more steps:\n\n1. Let the CLI install the dependencies when it asks, or pass `-y` to skip the question. If you decline, run the`npm install` lines it prints under`Next:` .\n2. Add the services the README lists, for example with `neon config add ai-gateway` .\n3. Put the values for the template's environment variables into your local `.env.local` or`.env` file.\n4. If you added services, deploy once with `neon deploy --env .env.local` so Neon provisions them and writes their credentials to your local env file.\n\nYou can then run the function locally with `neon dev`, make changes and deploy it again.\n\nKeep `--env .env.local` on the deploy command for any template with its own variables, because the deploy fails when those variables are undefined. The [function templates docs](https://neon.com/docs/compute/functions/templates) cover each step in more detail.\n\nOnce installed, the files are yours to edit. The CLI won't overwrite them with a newer version of the template. Also keep in mind that most templates don't check who is calling them, so add [authentication](https://neon.com/docs/compute/functions/authentication) before you share the URL of anything that calls a paid service.\n\n## Next steps\n\nPick whichever of these fits where you are:\n\n- Browse every template on [neon.com/functions/templates](https://neon.com/functions/templates) and add one to a project you already have.\n- Read [Use function templates](https://neon.com/docs/compute/functions/templates) for the full setup, including services and environment variables.\n- Publish your own template with a pull request on [`neondatabase/examples`](https://github.com/neondatabase/examples) , following[Contribute a function template](https://neon.com/docs/compute/functions/registry) .\n- Tell us which template you want next in the [Neon Discord](https://neon.com/discord) .", "url": "https://wpnews.pro/news/save-tokens-with-neon-function-templates", "canonical_source": "https://neon.com/blog/save-tokens-with-neon-function-templates", "published_at": "2026-11-05 12:00:00+00:00", "updated_at": "2026-11-05 17:22:13.011674+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["Neon", "Neon Function Registry", "Neon Functions", "Vercel", "Chat SDK", "Mastra", "Context.dev", "WorkOS"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/save-tokens-with-neon-function-templates", "markdown": "https://wpnews.pro/news/save-tokens-with-neon-function-templates.md", "text": "https://wpnews.pro/news/save-tokens-with-neon-function-templates.txt", "jsonld": "https://wpnews.pro/news/save-tokens-with-neon-function-templates.jsonld"}}