Skip to content
OpenAI logo

o3-mini

Text GenerationOpenAI

o3-mini is the lightweight, low-cost reasoning variant of o3, well suited to quick analytical tasks at scale.

Model Info
Context Window200,000 tokens
Terms and Licenselink
More informationlink
PricingView pricing in the Cloudflare dashboard

Usage

TypeScript
const response = await env.AI.run(
'openai/o3-mini',
{ messages: [{ content: 'What are the three laws of thermodynamics?', role: 'user' }] },
)
console.log(response)
There are a few ways people count the laws of thermodynamics, but a common approach (especially in basic texts) is to focus on these three:

1. First Law of Thermodynamics (Law of Energy Conservation)  
 • This law states that energy cannot be created or destroyed—only converted from one form to another. In a closed system, the total energy remains constant. For example, when you burn fuel, the chemical energy is converted into heat and work.

2. Second Law of Thermodynamics  
 • This law introduces the concept of entropy, a measure of disorder. It states that in any natural (irreversible) process, the total entropy of an isolated system increases (or remains constant in ideal reversible cases). This explains why heat flows spontaneously from hot to cold and why certain processes (like perpetual motion machines) are impossible.

3. Third Law of Thermodynamics  
 • The third law states that as the temperature of a system approaches absolute zero (0 Kelvin), the entropy of a perfect crystal approaches zero. This law implies that absolute zero is unattainable and provides a reference point for the measurement of entropy.

Note: There is also the Zeroth Law of Thermodynamics, which is sometimes considered foundational. It states that if two systems are each in thermal equilibrium with a third system, then they are in thermal equilibrium with each other. This law is crucial in defining temperature but is not always numbered among the “three” if one starts counting from the first law.

These laws together form the basis of classical thermodynamics, helping us understand energy flow, heat transfer, and the directionality of physical processes.

Examples

With System Message — Using a system message to set context
TypeScript
const response = await env.AI.run(
'openai/o3-mini',
{
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)
To read a JSON file in Python, you can use the built-in json module. This module provides methods for encoding and decoding JSON data. Typically, you'll want to use the json.load() function to read and parse JSON data from a file. Here’s a simple step-by-step example:

1. Import the json module.
2. Open the JSON file using the with context manager (this automatically closes the file after you're done).
3. Use json.load() to parse the file.

Below is the complete example code:

--------------------------------------------------
import json

# Open the JSON file and load its content
with open('data.json', 'r') as file:
    data = json.load(file)

# Now 'data' contains the JSON file content as a Python dictionary (or list, depending on JSON structure)
print(data)
--------------------------------------------------

Explanation:
• The with statement is used to open the file, which ensures that the file is properly closed even if an error occurs.
• The 'r' mode is specified to open the file in read mode.
• json.load(file) parses the JSON content and returns a Python object.
• The resulting data is stored in the variable data, which you can then work with as needed.

If you have any questions or need further assistance, feel free to ask!
Multi-turn Conversation — Continuing a conversation with context
TypeScript
const response = await env.AI.run(
'openai/o3-mini',
{
max_completion_tokens: 8192,
messages: [
{
content: 'I need help planning a road trip from San Francisco to Los Angeles.',
role: 'user',
},
{
content:
"I'd be happy to help! The drive is about 380 miles and takes roughly 5-6 hours. Would you like suggestions for scenic routes or interesting stops along the way?",
role: 'assistant',
},
{ content: 'Yes, what are some good places to stop?', role: 'user' },
],
},
)
console.log(response)
Great! When planning a road trip along the scenic coast (California's Highway 1), here are some must-see stops between San Francisco and Los Angeles:

1. Santa Cruz:  
   • Enjoy the laid-back vibe at the Santa Cruz Beach Boardwalk.  
   • Take a stroll by the beach or check out the local shops and cafés downtown.

2. Monterey & Cannery Row:  
   • Visit the famous Monterey Bay Aquarium, a highlight of the area.  
   • Walk along Cannery Row and relish the coastal views or even take a local boat tour.
   • If time allows, consider the 17-Mile Drive in nearby Pebble Beach for a fantastic coastline drive.

3. Carmel-by-the-Sea:  
   • This charming town offers art galleries, boutique shopping, and quaint cafés in a picturesque setting.  
   • Enjoy the beautiful white-sand Carmel Beach and a stroll through the fairy-tale village.

4. Big Sur:  
   • Drive through one of the most breathtaking stretches of coastline in the world.  
   • Stop at iconic landmarks like Bixby Creek Bridge or take in the views from Nepenthe.  
   • Enjoy a short hike or simply take in the ocean views over cliffs—just be sure to check road conditions, as parts of Highway 1 can be winding.

5. San Simeon/Hearst Castle:  
   • Explore Hearst Castle, a historic mansion with impressive architecture and art.  
   • Enjoy nearby coastal views and wildlife, including elephant seals which often hang out at the beaches.

6. Santa Barbara (Optional Stop):  
   • Once you start heading toward Los Angeles, a stop in Santa Barbara can be a relaxing break.  
   • Stroll through the downtown area, visit the historic Mission Santa Barbara or relax at the beach.

Depending on your schedule and interests, you can choose to spend more time in one area than another. For instance, if you're a nature lover, spending a day in Big Sur might be perfect for you. Alternatively, beer or foodie enthusiasts might enjoy more time exploring the eateries in Monterey or Santa Barbara.

Some additional tips:  
• Always check for road conditions and parking information especially in Big Sur, as it can get busy on weekends.  
• Consider making reservations at popular restaurants or attractions in advance.  
• Pack some snacks and water, as some stretches between stops can be remote.

Would you like more detailed itineraries for any of these stops, or do you have specific interests (like hiking, dining, or cultural attractions) that we should highlight?
Creative Writing — Longer completion for creative output
TypeScript
const response = await env.AI.run(
'openai/o3-mini',
{
max_completion_tokens: 8192,
messages: [
{
content: 'Write a short story opening about a detective finding an unusual clue.',
role: 'user',
},
],
},
)
console.log(response)
Detective Elena Marquez stood motionless in the dim glow of the abandoned warehouse, her eyes fixated on a peculiar object half-buried in layers of dust and cobwebs. Amidst scattered papers and defaced photographs, the unusual clue—a small porcelain figurine with an ethereal, almost luminescent crack running down its side—seemed to beckon her closer. Its delicate features, strangely out of place in this grim setting, whispered secrets of a long-forgotten past and hinted at connections far deeper than any ordinary case.

As she carefully lifted the figurine with gloved hands, Elena noted an inscription faintly etched along its base, its characters reminiscent of an undiscovered language. The artifact pulsed with an energy that both unnerved and fascinated her, a silent promise that solving its mystery might unravel the threads of a labyrinthine conspiracy. In that hushed moment, the detective realized that this was no random piece of debris—it was an intentional breadcrumb leading to a truth hidden beneath layers of time and deceit.
Streaming Response — Enable streaming for real-time output
TypeScript
const response = await env.AI.run(
'openai/o3-mini',
{
messages: [{ content: 'Explain the concept of recursion with a simple example.', role: 'user' }],
stream: true,
stream_options: { include_usage: true },
},
)
console.log(response)
Recursion is a technique in programming where a function calls itself to solve a problem. The function breaks the problem into smaller, similar subproblems until it reaches a simple case that can be solved directly—this is known as the base case. Once the base case is reached, the recursion stops, and the solutions to the smaller subproblems are combined to solve the original problem.

A simple example is calculating the factorial of a number. The factorial of a non-negative integer n (written as n!) is defined as:

  n! = n × (n-1) × (n-2) × ... × 1

By definition, 0! is 1. Using recursion, you can express the factorial function as:

  factorial(n) = n × factorial(n-1)

with the base case:

  factorial(0) = 1

Here’s a step-by-step explanation:

1. If n is 0, return 1 (base case).
2. Otherwise, return n multiplied by the factorial of (n-1).

For example, to compute 3!:
  • factorial(3) = 3 × factorial(2)
  • factorial(2) = 2 × factorial(1)
  • factorial(1) = 1 × factorial(0)
  • factorial(0) = 1 (base case)

Working back up:
  • factorial(1) = 1 × 1 = 1
  • factorial(2) = 2 × 1 = 2
  • factorial(3) = 3 × 2 = 6

Thus, 3! equals 6.

This example illustrates how recursion solves a problem by simplifying it step by step until it reaches a solution.

Parameters

frequency_penalty
numbermaximum: 2minimum: -2
max_completion_tokens
numberexclusiveMinimum: 0
max_tokens
numberexclusiveMinimum: 0
presence_penalty
numbermaximum: 2minimum: -2
response_format
stream
boolean
temperature
numbermaximum: 2minimum: 0
tool_choice
top_p
numbermaximum: 1minimum: 0

API Schemas (Raw)

Input
Output