Skip to main content
This guide walks through using OpenAI models with the AI Gateway. OpenAI is a built-in provider, so ngrok.ai offers managed inference for it—you can use OpenAI models without an OpenAI account of your own, or bring your own key.

Use ngrok.ai inference (no OpenAI account)

You can use OpenAI models without your own OpenAI account—ngrok.ai inference supplies the upstream credentials and bills the model cost through credits.
1

Create an access key and add credits

Follow the quickstart to create an access key and purchase credits in app.ngrok.ai.
2

Send requests

Point your SDK at the gateway with your access key:
from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.ngrok.ai/v1",
    api_key="ng-xxxxx-g1-xxxxx"  # Access key
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

Bring your own OpenAI key

Want requests billed to your own OpenAI account instead of through credits? Store your OpenAI key once—the gateway attaches it for you on every request.
1

Create an access key

Follow the quickstart to create an access key in app.ngrok.ai if you don’t have one yet.
2

Add your OpenAI key

Add a provider key for OpenAI. ngrok stores it encrypted, so it never has to live in your application or get shared around—and you can reuse it across as many access keys as you need.
3

Route to it with a configuration

Create an access key configuration with an OpenAI routing rule set to Bring your own API key, then assign it to your access key.
4

Keep sending your access key

Your code doesn’t change. Send the same access key as before—the gateway swaps in your OpenAI key before the request leaves for OpenAI.

Explicit provider routing

response = client.chat.completions.create(
    model="openai:gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

Available models

Browse the model catalog for the full list of OpenAI models you can call through the gateway.

Next steps