o4-mini

Text Generation • OpenAI

openai/o4-mini

  • Third-party
  • Zero data retention

OpenAI's fast, lightweight reasoning model optimized for multi-step problem solving at lower 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)$1.10</li><li>Output (per 1M tokens)$4.40</li><li>Cached input (per 1M tokens)$0.275</li></ul>

Usage

const response = await env.AI.run(
  'openai/o4-mini',
  { 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/o4-mini",
  "messages": [
    {
      "content": "What are the three laws of thermodynamics?",
      "role": "user"
    }
  ]
}'
Here are the three (classical) laws of thermodynamics:

1. First Law (Conservation of Energy)  
     – Statement: Energy can neither be created nor destroyed, only converted from one form to another.  
     – Formulation: ΔU = Q – W  
      • ΔU is the change in internal energy of the system  
      • Q is heat added to the system  
      • W is work done by the system  

2. Second Law (Entropy Increase)  
     – Statement: In any spontaneous process, the total entropy of an isolated system never decreases; it increases for irreversible processes and remains constant for reversible ones.  
     – Key consequences:  
      • Heat cannot spontaneously flow from cold to hot (Clausius statement)  
      • No heat engine can be 100% efficient (Kelvin–Planck statement)  

3. Third Law (Unattainability of Absolute Zero)  
     – Statement: As the temperature of a perfect crystalline substance approaches absolute zero (0 K), its entropy approaches a constant minimum (often taken as zero).  
     – Consequence: It is impossible to reach absolute zero in a finite number of steps.
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "annotations": [],
        "content": "Here are the three (classical) laws of thermodynamics:\n\n1. First Law (Conservation of Energy)  \n     – Statement: Energy can neither be created nor destroyed, only converted from one form to another.  \n     – Formulation: ΔU = Q – W  \n      • ΔU is the change in internal energy of the system  \n      • Q is heat added to the system  \n      • W is work done by the system  \n\n2. Second Law (Entropy Increase)  \n     – Statement: In any spontaneous process, the total entropy of an isolated system never decreases; it increases for irreversible processes and remains constant for reversible ones.  \n     – Key consequences:  \n      • Heat cannot spontaneously flow from cold to hot (Clausius statement)  \n      • No heat engine can be 100% efficient (Kelvin–Planck statement)  \n\n3. Third Law (Unattainability of Absolute Zero)  \n     – Statement: As the temperature of a perfect crystalline substance approaches absolute zero (0 K), its entropy approaches a constant minimum (often taken as zero).  \n     – Consequence: It is impossible to reach absolute zero in a finite number of steps.",
        "refusal": null,
        "role": "assistant"
      }
    }
  ],
  "created": 1776470984,
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "id": "chatcmpl-DVnXkjut2BEk7At18pcFMPV5TOSoc",
  "model": "o4-mini-2025-04-16",
  "object": "chat.completion",
  "service_tier": "default",
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 505,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 192,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens": 15,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 0
    },
    "total_tokens": 520
  }
}

Examples

<details>

<summary>With System Message — Using a system message to set context</summary>

const response = await env.AI.run(
  'openai/o4-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)
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/o4-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"
    }
  ]
}'

```` Here’s the most common way, using Python’s built-in json module:

```python import json