o3
Text Generation • OpenAI
openai/o3
- Third-party
- Zero data retention
o3 is OpenAI’s general-purpose reasoning model, balancing strong analytical performance with reasonable latency and cost.
| Model Info | |
|---|---|
| Context Window ↗ | 200,000 tokens |
| Terms and License | link ↗ |
| More information | link ↗ |
| Zero data retention | Yes |
| Request formats | Responses, Chat Completions |
| Pricing | <ul><li>Input (per 1M tokens)$2.00</li><li>Output (per 1M tokens)$8.00</li><li>Cached input (per 1M tokens)$0.50</li></ul> |
Usage
const response = await env.AI.run(
'openai/o3',
{ messages: [{ content: 'What are the three laws of thermodynamics?', role: 'user' }] },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "openai/o3",
"messages": [
{
"content": "What are the three laws of thermodynamics?",
"role": "user"
}
]
}'
The three fundamental laws of thermodynamics can be stated informally as follows:
1. First Law (Law of Energy Conservation)
Energy cannot be created or destroyed; it can only change form. For any closed system the change in internal energy equals the heat added to the system minus the work done by the system.
2. Second Law (Law of Entropy)
In any natural (spontaneous) process the total entropy of an isolated system always increases or, at best, remains constant. Equivalently, heat cannot spontaneously flow from a colder body to a hotter body, and no heat engine operating in a cycle can be 100 % efficient.
3. Third Law (Absolute-zero Limit)
As the temperature of a perfect crystalline substance approaches absolute zero, its entropy approaches a minimum value (taken as zero). Therefore it is impossible to reach absolute zero by any finite series of processes.
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"annotations": [],
"content": "The three fundamental laws of thermodynamics can be stated informally as follows:\n\n1. First Law (Law of Energy Conservation) \n Energy cannot be created or destroyed; it can only change form. For any closed system the change in internal energy equals the heat added to the system minus the work done by the system.\n\n2. Second Law (Law of Entropy) \n In any natural (spontaneous) process the total entropy of an isolated system always increases or, at best, remains constant. Equivalently, heat cannot spontaneously flow from a colder body to a hotter body, and no heat engine operating in a cycle can be 100 % efficient.\n\n3. Third Law (Absolute-zero Limit) \n As the temperature of a perfect crystalline substance approaches absolute zero, its entropy approaches a minimum value (taken as zero). Therefore it is impossible to reach absolute zero by any finite series of processes.",
"refusal": null,
"role": "assistant"
}
}
],
"created": 1777319513,
"gatewayMetadata": {
"keySource": "Unified"
},
"id": "chatcmpl-DZMHh2qmPkLVJgEKu27EuhV3Zx6yU",
"model": "o3-2025-04-16",
"object": "chat.completion",
"service_tier": "default",
"system_fingerprint": null,
"usage": {
"completion_tokens": 203,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens": 15,
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0
},
"total_tokens": 218
}
}
Examples
<details>
<summary>With System Message — Using a system message to set context</summary>
const response = await env.AI.run(
'openai/o3',
{
messages: [
{ content: 'You are a helpful coding assistant specializing in Python.', role: 'system' },
{ content: 'How do I read a JSON file in Python?', role: 'user' },
],
},
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "openai/o3",
"messages": [
{
"content": "You are a helpful coding assistant specializing in Python.",
"role": "system"
},
{
"content": "How do I read a JSON file in Python?",
"role": "user"
}
]
}'
```` Reading a JSON file in Python is straightforward with the built-in json module. Below are the most common patterns, from the simplest one-liner to approaches that add error handling, use pathlib, or parse to a pandas DataFrame.
──────────────────────── 1. Quick start (basic usage) ────────────────────────
import json
with open("data.json", "r", encoding="utf-8") as f:
data = json.load(f) # `data` is now a Python dict or list
• json.load() converts the JSON in the file to native Python objects (dict, list, int, float, str, bool, None).
• encoding="utf-8" is often optional but safest—especially on Windows.
──────────────────────────────────────────────── 2. Using pathlib (cleaner path handling, cross-platform) ───────────────────────────────────────────────────────
from pathlib import Path
import json
json_path = Path("path") / "to" / "data.json"
with json_path.open(encoding="utf-8") as f:
data = json.load(f)
────────────────────────────────────────────── 3. Adding error handling / validation ──────────────────────────────────────────────
import json
from pathlib import Path
def read_json(path):
try:
with Path(path).open(encoding="utf-8") as f:
return json.load(f)
except FileNotFoundError:
print(f"File not found: {path}")
except json.JSONDecodeError as exc:
print(f"Invalid JSON in {path}: {exc}")
return None
data = read_json("data.json")
────────────────────────────────────────────────────── 4. Loading a JSON lines (NDJSON) file (one JSON per line) ──────────────────────────────────────────────────────
import json
records = []
with open("data.ndjson", encoding="utf-8") as f:
for line in f:
records.append(json.loads(line))
────────────────────────────────────── 5. Directly into a pandas DataFrame ────────────────────────────────────── If your JSON is an array of objects (list of dicts) or NDJSON: ```python import pandas as pd
df = pd.read_json("data.json") # Works for many cases
