Skip to main content
These examples use the direct API host, https://api.nano-gpt.com. It has no IPv6 address, so clients with only IPv6 should use https://nano-gpt.com with the same paths. See API Hosts.

Using the Vercel AI SDK with NanoGPT

NanoGPT works with the AI SDK through the @ai-sdk/openai-compatible package. You only need a base URL and an API key; no NanoGPT-specific package is required.

Setup

  1. Get your API key from nano-gpt.com/api and set it as a server-side environment variable:
  2. Install the AI SDK and its OpenAI-compatible provider:

Create the provider

The apiKey setting sends your key as a Bearer token in the Authorization header.

Generate text

Stream text

Models

Pass any NanoGPT text model ID to the provider. GET /api/v1/models lists the current IDs, and ?detailed=true adds each model’s context length and capabilities. Tool calling, image input and reasoning depend on the model you select. These examples were checked with ai 7.1.1 and @ai-sdk/openai-compatible 3.0.100. The SDK calls /api/v1/chat/completions.