Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 6 min read How-to mediumAdept

How to build and authenticate an AI API using Modal, Neon, and Unkey

An OpenAI Whisper transcription API built with FastAPI and deployed on Modal, which persists transcripts to a Neon serverless Postgres database via psycopg2. Requests are gated by API keys verified through Unkey's Python SDK. The walkthrough covers defining the Modal image and stub, writing uploads to a temp file for Whisper, creating the database and table with neonctl and psql, passing the connection string as a Modal secret, and checking the Authorization header against Unkey before returning a permanent link to the transcript.

Assumes: Python web APIsFastAPI basicsPostgreSQL basics

Related posts

  • Deploy a Serverless FastAPI App with Neon Postgres and AWS App Runner at any scale

    Neon mediumAdept

    A step-by-step setup for a Python API built with FastAPI and SQLModel, backed by Neon serverless Postgres and deployed to AWS App Runner with automatic deploys on each Git push. The database connection string is stored as a SecureString in AWS SSM Parameter Store and injected through apprunner.yaml secrets, with access granted by an IAM instance role. Practical details include using psycopg 3 by rewriting the URL scheme to postgresql+psycopg, and setting SQLAlchemy pool_recycle=300 to match Neon's 5-minute compute auto-suspend. pool_pre_ping is offered as an alternative that adds connection latency.

  • Neon for Agent Platforms: A Companion Skill for the AI Agent Program

    Neon mediumAdept

    neon-for-agent-platforms is an open-source companion Agent Skill and set of TypeScript scripts for running fleets of Neon Postgres databases on agent platforms. It covers a dual-org model that separates sponsored free-tier and paid customers, with one project per tenant transferred to the paid org on upgrade. It also covers copy-on-write dev and preview branches with shorter suspend timeouts to keep costs predictable, branch-based compound checkpoints, and the consumption API for per-customer cost attribution. Both skills install via npx, and the scripts can also be run directly against a Neon API key and org ID.

  • Storing Vercel's AI SDK chat messages in a Turso database

    Turso mediumAdept

    Vercel AI SDK's useChat hook doesn't persist conversations, so chat history can be stored in a Turso (libSQL) table and reloaded on page render. A server component queries the messages table and passes rows as initialMessages to useChat. The API route inserts the user's last message before calling streamText, and an onFinish callback inserts the assistant's reply. Suggested extensions include a chats/sessions table with foreign keys, background persistence via server actions, or a database per user or chat.

  • Building an AI-powered ChatBot using Vercel, OpenAI, and Postgres

    Neon mediumAdept

    A ChatGPT-style documentation assistant (Ask Neon) is built by storing OpenAI text-embedding-ada-002 vectors in Postgres with pgvector, retrieving context by cosine distance, and feeding it to text-davinci-003 from a Vercel Edge Function. A window-function query caps retrieved context at a cumulative 1,500 tokens to fit the 4,096-token model limit, and an ivfflat index (lists ≈ 4·sqrt(rows)) speeds up the similarity search. Neon's WebSocket-based serverless driver works around Edge Functions' lack of TCP, and streaming completions via SSE parsing return answers faster. User feedback is stored for later fine-tuning.

  • Building a GPT Backed by a Heroku-Deployed API

    Heroku Engineering mediumAdept

    A custom OpenAI GPT can be backed by a simple Express API on Heroku that answers natural-language questions about an employee directory. The API makes two Chat Completions calls: one turns the user's question into a PostgreSQL query using the table schema in a system prompt and JSON response format, and a second turns the returned rows into a readable answer, resending the schema because the models keep no memory between requests. The walkthrough covers bearer-token auth, environment configuration, local curl testing, Heroku deployment with Postgres, and configuring the GPT action. It also warns that all data leaves Heroku's trust boundary to reach OpenAI.

The quest for software engineering knowledge.

Look:
Layout: