Get started with OpenAI API

OpenAI API provides a unified, OpenAI-compatible API that gives you access to the OpenAI model family through a single endpoint. It handles failover and routes requests to the healthy path. Get started with just a few lines of code.

OpenAI SDK Compatible

OpenAI API works as a drop-in replacement for the OpenAI SDK. Just change the base URL and API key — your existing code works immediately.

API Endpoint

Use the global endpoint for all requests: https://api.openaiapi.lol/v1.

Using the OpenAI SDK

The fastest way to get started. Use the official OpenAI SDK with the OpenAI API base URL.

typescriptchat.completions
import OpenAI from 'openai';

const openai = new OpenAI({
  baseURL: 'https://api.openaiapi.lol/v1',
  apiKey: process.env.OPENAIA_API_KEY,
});

const completion = await openai.chat.completions.create({
  model: 'openai/gpt-4o',
  messages: [{ role: 'user', content: 'What is the meaning of life?' }],
});

console.log(completion.choices[0].message);

Using the API Directly

Send requests directly to the OpenAI API endpoint.

cURLBase URL: https://api.openaiapi.lol/v1
curl https://api.openaiapi.lol/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAIA_API_KEY" \
  -d '{
    "model": "openai/gpt-4o",
    "messages": [{ "role": "user", "content": "What is the meaning of life?" }]
  }'

Streaming

OpenAI API supports streaming responses via Server-Sent Events (SSE). Add stream: true to your request to receive tokens as they are generated.

typescriptstreaming
const stream = await openai.chat.completions.create({
  model: 'openai/gpt-4o',
  messages: [{ role: 'user', content: 'Tell me a story' }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

Model Naming

OpenAI API uses a standard provider/model-name format. For example:

  • openai/gpt-5.2 — GPT-5.2
  • openai/gpt-4o — GPT-4o
  • openai/gpt-4o-mini — GPT-4o Mini
  • openai/gpt-image-1 — GPT Image 1

Browse every available model on the Models page.

Next Steps

  • Read the model catalog to choose the right model for each workload.
  • Set spending limits and budget alerts before you route production traffic.
  • Compare plans on the pricing page and pick your included allowance.
Quickstart — Send Your First OpenAI API Request