GPT-5.1

Text Generation • OpenAI

openai/gpt-5.1

  • Third-party
  • Zero data retention

GPT-5.1 is OpenAI’s incremental improvement over GPT-5, with stronger coding, reasoning, and writing.

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)$1.25</li><li>Output (per 1M tokens)$10.00</li><li>Cached input (per 1M tokens)$0.125</li></ul>

Usage

const response = await env.AI.run(
  'openai/gpt-5.1',
  { 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-5.1",
  "messages": [
    {
      "content": "What are the three laws of thermodynamics?",
      "role": "user"
    }
  ]
}'
The three classical laws of thermodynamics (often listed as 0th–3rd, but you asked for three) are:

**First Law (Conservation of Energy)**  
Energy cannot be created or destroyed, only transformed from one form to another.  
Mathematically for a system:  
\[
\Delta U = Q - W
\]  
where ΔU is change in internal energy, Q is heat added to the system, and W is work done by the system.

**Second Law (Direction of Processes / Entropy)**  
The total entropy of an isolated system never decreases; it either increases or, in an ideal reversible process, stays constant.  
This implies:
- Heat flows spontaneously from hot to cold, not the reverse.
- No heat engine can be 100% efficient.

**Third Law (Absolute Zero and Entropy)**  
As the temperature of a perfect crystalline substance approaches absolute zero (0 K), its entropy approaches a minimum value (often taken as zero).  
Consequence: It is impossible, by any finite number of steps, to cool a system all the way to absolute zero.
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "annotations": [],
        "content": "The three classical laws of thermodynamics (often listed as 0th–3rd, but you asked for three) are:\n\n**First Law (Conservation of Energy)**  \nEnergy cannot be created or destroyed, only transformed from one form to another.  \nMathematically for a system:  \n\\[\n\\Delta U = Q - W\n\\]  \nwhere ΔU is change in internal energy, Q is heat added to the system, and W is work done by the system.\n\n**Second Law (Direction of Processes / Entropy)**  \nThe total entropy of an isolated system never decreases; it either increases or, in an ideal reversible process, stays constant.  \nThis implies:\n- Heat flows spontaneously from hot to cold, not the reverse.\n- No heat engine can be 100% efficient.\n\n**Third Law (Absolute Zero and Entropy)**  \nAs the temperature of a perfect crystalline substance approaches absolute zero (0 K), its entropy approaches a minimum value (often taken as zero).  \nConsequence: It is impossible, by any finite number of steps, to cool a system all the way to absolute zero.",
        "refusal": null,
        "role": "assistant"
      }
    }
  ],
  "created": 1777319793,
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "id": "chatcmpl-DZMMDjkjm2G9LOk72IMGhbyvdpRFX",
  "model": "gpt-5.1-2025-11-13",
  "object": "chat.completion",
  "service_tier": "default",
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 236,
    "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": 251
  }
}

Examples

<details>

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

const response = await env.AI.run(
  'openai/gpt-5.1',
  {
    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-5.1",
  "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, use the built-injson` module.

Basic example

```python import json