
5 minutes read
Start using GPT‑5 through OpenAI's API (soon!)
Table of contents
Introduction to GPT‑5
GPT‑5 is OpenAI’s incredible new flagship model for the second half of 2025.
If you are new to large language models, take a moment to skim my plain‑English explainer on how GPT‑style LLMs work. It will help you understand how they work and you will be able to use them better.
Ready? Let’s build your first GPT‑5 request.
Create an account to get your GPT‑5 API key
- Create an account or sign in.
-
Confirm your email address.
-
Open the Billing overview page and add credit or a payment method so your keys work right away. (The free‑credit program ended mid‑2024.)
-
Generate your first API key for GPT‑5. Keys are shown once; paste it into a password manager immediately.
Got your key? Great. Time to hit the API.
How to make your first request to GPT‑5
Open your terminal and run this cURL snippet:
macOS and Linux:
curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ https://api.openai.com/v1/chat/completions -d '{ "model": "gpt-5", "messages": [ { "role": "system", "content": "You are an assistant." }, { "role": "user", "content": "Hello!" } ] }'
Windows command prompt (one‑liner):
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer %OPENAI_API_KEY%" https://api.openai.com/v1/chat/completions -d "{ \"model\": \"gpt‑5\", \"messages\": [{\"role\":\"user\",\"content\":\"Hello!\"}] }"
Pro tip: The alias gpt‑5 always points at the newest GPT-5 weights, so you enjoy silent upgrades.
Token budget: a single call can swallow up to 1,000,000 tokens (roughly 750,000 English words).
How to enable JSON mode with GPT‑5
GPT‑5 obeys JSON schemas the same way GPT‑5 did. Add a response_format
field and you get rock‑solid JSON every time.
curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ https://api.openai.com/v1/chat/completions -d '{ "model": "gpt-5", "messages": [ { "role": "system", "content": "Serve answers as tight JSON." }, { "role": "user", "content": "Solve 8x + 31 = 2." } ], "response_format": { "type": "json_schema", "json_schema": { "strict": true, "schema": { "type": "object", "properties": { "steps": { "type": "array", "items": { "type": "string" } }, "final_answer": { "type": "string" } }, "required": ["steps", "final_answer"], "additionalProperties": false } } } }'
Keep schemas lean; every character counts against your million‑token window.
About the 1 million tokens context window
The 1 million limit is real but your rate‑limit tier must be high enough to feed that many tokens per minute. Many tier‑1 organizations report hitting HTTP 429 around 30K tokens per minute. Double‑check your org’s actual quota before chunking a megaprompt.
FYI, hitting higher tiers requires some amount of spendings.
Vision and multimodal (quick-start)
Nowadays, Large Language Models are also trained on other things than just text. That’s what we call multimodality. For instance, GPT is trained on images, which allows it to have vision capabilities.
GPT-5 supports these formats and sizes:
- Formats: JPEG, PNG, WEBP, and HEIC.
- Limits: ≤ 20 MB per image and ≤ 20 images per request.
My recommendation: keep images ~1-2 MP. Larger adds latency with little gain.
Then, how do you attach images to your message to GPT? Here are two ways:
- Encode it to base64. This is best for prototyping or working offline.
- Pass an URL. This is the best, fastest, and my favorite way.
Send images to GPT-5
Your first option, and the best, if to send an URL:
curl https://api.openai.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "gpt-5", "messages": [ { "role": "user", "content": [ { "type": "image_url", "image_url": { "url": "https://cdn.example.com/slide.jpg" } }, { "type": "text", "text": "Describe this slide." } ] } ] }'
The second option is to swap the url
value above for a data URL:
"image_url": { "url": "data:image/jpeg;base64,$(base64 -w0 slide.jpg)" }
Pro tips
- One image per message keeps the model focused; for a gallery, add a short caption to each image part.
- Put your text prompt after the image in the same message for better results.
- For long conversations, URLs are lighter than repeatedly sending Base64.
GPT‑5 pricing
Model | Input (per 1 M) | Output (per 1 M) |
---|---|---|
gpt‑5 (1 M context) | $?.?? | $?.?? |
gpt‑5‑mini (1 M context) | $?.?? | $?.?? |
gpt‑5‑nano (1 M context) | $?.?? | $?.?? |
gpt‑4.1 (1 M context) | $2.00 | $8.00 |
gpt‑4.1‑mini (1 M context) | $0.40 | $1.60 |
gpt‑4.1‑nano (1 M context) | $0.10 | $0.40 |
GPT-5 (full), mini, or nano?
As you saw in the pricing table, GPT-5 is available in three flavors: full, mini, and nano. Each are designed for different needs. They all share the 1 million-token context window, but differ significantly in speed, cost, and use-case sweet spots. Here’s how you pick yours:
-
GPT-5 (full): This is the flagship. It’s powerful, versatile, and handles deep reasoning tasks, massive documents, complex coding, and sophisticated multimodal prompts. When you need uncompromising quality, choose GPT-5.
-
GPT-5 mini: Around twice as fast as the flagship and about 83% cheaper, mini hits the sweet spot for real-time applications, live chats, support bots, or any scenario where you want fast responses without draining your budget.
-
GPT-5 nano: The smallest sibling but also the quickest and cheapest. Nano is ideal for simple classification tasks, auto-completion features, mobile apps, or anything that runs at scale. At about 95% cheaper than full GPT-5, nano makes deploying large-scale AI affordable for everyone.
Did you like this article? Then, keep learning:
- Build a ChatGPT plugin using Laravel for enhanced app interaction
- Explore GPT-3.5 Turbo's API to understand earlier GPT versions
- Get started step-by-step with GPT-4 Turbo's API for practical insights
- Use GPT-4o mini's API for a cost-effective GPT experience
- Access and use GPT-4o's API with an easy step-by-step guide
- Learn how GPT language models work, complementing GPT-5 API usage
- Use PHP to leverage OpenAI's API easily in your projects
- Get the best out of GPT-4.1's API with this quick guide
0 comments