OhMyGPT

Quickstart

Send your first API request in under 5 minutes.

OhMyGPT provides a unified, OpenAI-compatible API that routes requests to hundreds of AI models. You can use the OpenAI SDK, any OpenAI-compatible client, or raw HTTP requests.

Prerequisites

RequirementDetails
AccountRegister at next.ohmygpt.com
API KeyCreate one at API Keys
CreditAdd balance via the Billing page

Protect your API keys. Never commit them to public repositories. Use environment variables to keep keys out of your codebase.

Base URL

All API requests go through a single base URL:

https://api.ohmygpt.com/v1

For users in different regions, alternative endpoints are available:

EndpointDescriptionRecommended for
https://api.ohmygpt.comDirect US serverUsers in the US
https://apic.ohmygpt.comCloudflare CDN (Pro)Users outside the US
https://c-z0-api-01.hash070.comChina-optimized CDNUsers in mainland China

Send your first request

from openai import OpenAI

client = OpenAI(
    base_url="https://api.ohmygpt.com/v1",
    api_key="<OHMYGPT_API_KEY>",
)

completion = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "What is the meaning of life?"}
    ]
)

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

Response structure

A successful response contains:

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The meaning of life is..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 14,
    "completion_tokens": 125,
    "total_tokens": 139
  }
}
FieldDescription
choices[0].message.contentThe model's response text
usage.total_tokensTotal tokens consumed (used for billing)
finish_reasonWhy the model stopped: stop, length, or tool_calls

Common errors

CodeMeaningSolution
401Invalid API keyCheck that your key is correct and active
402Insufficient balanceAdd credit at Billing
429Rate limitedReduce request frequency or upgrade your tier
502Model unavailableTry a different model or wait and retry

Next steps

How is this guide?

Last updated on

On this page