GPT-4o mini

Text Generation • OpenAI

openai/gpt-4o-mini

  • Third-party
  • Zero data retention

GPT-4o Mini is the lightweight, low-cost variant of GPT-4o, well suited to high-volume tasks with multimodal inputs.

Model Info
Context Window ↗ 128,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)$0.075</li><li>Output (per 1M tokens)$0.30</li><li>Cached input (per 1M tokens)$0.0375</li></ul>

Usage

const response = await env.AI.run(
  'openai/gpt-4o-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/gpt-4o-mini",
  "messages": [
    {
      "content": "What are the three laws of thermodynamics?",
      "role": "user"
    }
  ]
}'
The three laws of thermodynamics are fundamental principles that describe the behavior of energy and matter in physical systems. Here’s a brief overview of each:

1. **Zeroth Law of Thermodynamics**: Though it was formulated after the first three laws, it's often referred to as the "zeroth" law. 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 forms the basis for the concept of temperature.

2. **First Law of Thermodynamics (Law of Energy Conservation)**: This law states that energy cannot be created or destroyed, only transformed from one form to another. In a closed system, the change in internal energy is equal to the heat added to the system minus the work done by the system. Mathematically, it's often expressed as:
   \[
   \Delta U = Q - W
   \]
   where \( \Delta U \) is the change in internal energy, \( Q \) is the heat added to the system, and \( W \) is the work done by the system.

3. **Second Law of Thermodynamics**: This law introduces the concept of entropy, stating that the total entropy of an isolated system can never decrease over time. It also implies that processes occur in a direction that increases the overall entropy of the universe. This law explains why some energy transformations are not 100% efficient and why heat flows spontaneously from hot to cold bodies.

4. **Third Law of Thermodynamics**: This law states that as the temperature of a system approaches absolute zero, the entropy of a perfect crystal approaches zero. It helps define the absolute temperature scale and indicates that it is impossible to reach absolute zero in a finite number of steps.

These laws are foundational to the study of physics and chemistry, affecting various fields, including engineering, biology, and materials science.
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": null,
      "message": {
        "annotations": [],
        "content": "The three laws of thermodynamics are fundamental principles that describe the behavior of energy and matter in physical systems. Here’s a brief overview of each:\n\n1. **Zeroth Law of Thermodynamics**: Though it was formulated after the first three laws, it's often referred to as the \"zeroth\" law. 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 forms the basis for the concept of temperature.\n\n2. **First Law of Thermodynamics (Law of Energy Conservation)**: This law states that energy cannot be created or destroyed, only transformed from one form to another. In a closed system, the change in internal energy is equal to the heat added to the system minus the work done by the system. Mathematically, it's often expressed as:\n   \\[\n   \\Delta U = Q - W\n   \\]\n   where \\( \\Delta U \\) is the change in internal energy, \\( Q \\) is the heat added to the system, and \\( W \\) is the work done by the system.\n\n3. **Second Law of Thermodynamics**: This law introduces the concept of entropy, stating that the total entropy of an isolated system can never decrease over time. It also implies that processes occur in a direction that increases the overall entropy of the universe. This law explains why some energy transformations are not 100% efficient and why heat flows spontaneously from hot to cold bodies.\n\n4. **Third Law of Thermodynamics**: This law states that as the temperature of a system approaches absolute zero, the entropy of a perfect crystal approaches zero. It helps define the absolute temperature scale and indicates that it is impossible to reach absolute zero in a finite number of steps.\n\nThese laws are foundational to the study of physics and chemistry, affecting various fields, including engineering, biology, and materials science.",
        "refusal": null,
        "role": "assistant"
      }
    }
  ],
  "created": 1777319548,
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "id": "chatcmpl-DZMIGfjLc8l4VDEpWs4s7mSFBSVSy",
  "model": "gpt-4o-mini-2024-07-18",
  "object": "chat.completion",
  "service_tier": "default",
  "system_fingerprint": "fp_3d695acdac",
  "usage": {
    "completion_tokens": 382,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens": 16,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 0
    },
    "total_tokens": 398
  }
}

Examples

<details>

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

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

``` To read a JSON file in Python, you can use the built-injson` module, which provides methods for parsing JSON data. Here’s a step-by-step guide on how to do this:

  1. Import the json module: This module allows you to work with JSON data easily.
  2. Open the JSON file: Use Python's built-in open() function to access the file.
  3. Load the JSON data: Use the json.load() function to parse the JSON data in the file.

Here is a simple example:

Example: Reading a JSON file

Assuming you have a JSON file named data.json with the following content:

{
    "name": "John",
    "age": 30,
    "city": "New York"
}

Here is how you can read this JSON file in Python:

```python import json