Skip to main content
OpenAI provides GPT and o-series models. The AI Gateway supports OpenAI as a managed provider—no OpenAI account needed—and also works with your own OpenAI API key.

Managed keys setup

No OpenAI account needed. Follow the quickstart to create your gateway and API key, then point your SDK at the gateway:
from openai import OpenAI

client = OpenAI(
    base_url="https://your-ai-gateway.ngrok.app/v1",
    api_key="ng-xxxxx-g1-xxxxx"  # Your AI Gateway API Key
)

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

print(response.choices[0].message.content)

Attach your own key

Attach your OpenAI key to your AI Gateway API Key. ngrok encrypts and stores it server-side, so clients only ever send your AI Gateway API Key.
1

Get an OpenAI API key

Create an account at platform.openai.com and generate an API key. Keys start with sk-proj-.
2

Attach the key

ngrok api ai-gateway-provider-keys create \
  --ai-gateway-api-key-id aigk_xxxxx \
  --provider-id openai \
  --description "My OpenAI Key" \
  --value sk-proj-...
3

Make a request

Use your AI Gateway API Key—the gateway resolves the OpenAI key server-side.
from openai import OpenAI

client = OpenAI(
    base_url="https://your-ai-gateway.ngrok.app/v1",
    api_key="ng-xxxxx-g1-xxxxx"  # Your AI Gateway API Key
)

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

print(response.choices[0].message.content)
See Attaching Provider Keys for key rotation, listing, and removing attached keys.

Explicit provider routing

Use the openai: prefix to force routing to OpenAI specifically:
response = client.chat.completions.create(
    model="openai:gpt-4o",  # Always routes to OpenAI, not another provider
    messages=[{"role": "user", "content": "Hello!"}]
)
This is useful in multi-provider setups where the same model name might exist on multiple providers.

Available models

See the model catalog for the full list of supported models and their context windows.

Next steps