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
| Requirement | Details |
|---|---|
| Account | Register at next.ohmygpt.com |
| API Key | Create one at API Keys |
| Credit | Add 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/v1For users in different regions, alternative endpoints are available:
| Endpoint | Description | Recommended for |
|---|---|---|
https://api.ohmygpt.com | Direct US server | Users in the US |
https://apic.ohmygpt.com | Cloudflare CDN (Pro) | Users outside the US |
https://c-z0-api-01.hash070.com | China-optimized CDN | Users 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
}
}| Field | Description |
|---|---|
choices[0].message.content | The model's response text |
usage.total_tokens | Total tokens consumed (used for billing) |
finish_reason | Why the model stopped: stop, length, or tool_calls |
Common errors
| Code | Meaning | Solution |
|---|---|---|
| 401 | Invalid API key | Check that your key is correct and active |
| 402 | Insufficient balance | Add credit at Billing |
| 429 | Rate limited | Reduce request frequency or upgrade your tier |
| 502 | Model unavailable | Try a different model or wait and retry |
Next steps
How is this guide?
Last updated on
