Skip to main content
This quickstart uses AI Gateway API Keys with ngrok-managed credits. If you’d rather bring your own OpenAI, Anthropic, or other provider keys, see Bring Your Own Keys.

Before you start

You’ll need an ngrok account on the Pay-as-you-go plan.
1

Create an AI Gateway

Open the New AI Gateway form. Enter a URL for your endpoint (for example, https://your-ai-gateway.ngrok.app) and click Create & Configure.
2

Purchase Credits

Purchase at least $5.00 in credits. Credits are required to use AI Gateway API Keys.
3

Create an API Key

On your gateway’s detail page, go to the API Keys tab and click New API Key. Copy the key immediately—it’s only shown once.
4

Make your first request

Point your OpenAI SDK at the gateway using your API key:
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://your-ai-gateway.ngrok.app/v1",
  apiKey: "ng-xxxxx-g1-xxxxx"
});

const res = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello, world!" }]
});

Next steps