{ "model_id": "google/gemini-4-carbon", "name": "Gemini 4 Carbon", "description": "Google's most capable Gemini 4 reasoning model, built for complex software engineering, math and science problems, autonomous multi-step agents, and long outputs up to 1M tokens.", "task": "Text Generation", "tags": [ "LLM", "Multimodal", "Reasoning", "Agentic", "Coding" ], "context_length": 1048576, "max_output_tokens": 65536, "schema_version": "1.0.0", "pricing": { "Input tokens (per 1M)": 2, "Output tokens (per 1M)": 10, "Cached input tokens (per 1M)": 0.1 }, "examples": [ { "name": "Simple Question", "description": "Basic generateContent request", "input": { "contents": [ { "parts": [ { "text": "What are the key differences between optimistic and pessimistic concurrency control in distributed systems?" } ], "role": "user" } ] }, "output": { "text": "In distributed systems, concurrency control ensures that multiple nodes or clients can access and modify shared data simultaneously without corrupting it or violating consistency guarantees. \n\nThe fundamental difference between **Pessimistic Concurrency Control (PCC)** and **Optimistic Concurrency Control (OCC)** lies in how they anticipate and handle data conflicts\u2014a challenge that is heavily amplified in distributed environments due to network latency, partial failures, and lack of a global clock.\n\nHere are the key differences between the two approaches in distributed systems:\n\n---\n\n### 1. Core Philosophy & Execution Flow\n* **Pessimistic (PCC):** Assumes conflicts are **likely**. A transaction acquires exclusive or shared locks on the data across the relevant nodes *before* reading or modifying it. Other transactions trying to access the same data are blocked until the lock is released. *(\u201cAsk for permission.\u201d)*\n* **Optimistic (OCC):** Assumes conflicts are **rare**. Transactions execute locally without acquiring locks. They read data (often noting a version number or timestamp), compute changes, and validate at **commit time** whether another node modified the data in the interim. If a conflict is detected, the transaction aborts and retries. *(\u201cAsk for forgiveness.\u201d)*\n\n### 2. Network Overhead and Latency\n* **Pessimistic:** High upfront network overhead. Acquiring and releasing distributed locks requires multiple network round-trips (often using protocols like Two-Phase Locking combined with Two-Phase Commit, or external coordinators like ZooKeeper/etcd) before work can safely finish. Locks are held across network boundaries, extending lock duration due to network latency.\n* **Optimistic:** Low upfront latency. Reads and local computations require minimal coordination. Network coordination only happens during the final validation/commit phase (e.g., via an atomic Compare-And-Swap operation or distributed consensus). However, if a conflict occurs, the entire network cost is wasted and must be repeated.\n\n### 3. Handling Partial Failures and Node Crashes\nIn a distributed system, nodes can crash or experience network partitions at any time.\n* **Pessimistic:** Vulnerable to **blocking on failure**. If a client or coordinator node crashes while holding a distributed lock, that data becomes unavailable to the rest of the cluster until a lease/timeout expires and recovery protocols run.\n* **Optimistic:** Highly resilient to slow or crashing clients. Because no locks are held during the read and compute phases, a crashed client does not block any other nodes in the system from making progress.\n\n### 4. Deadlocks vs. Livelocks (Starvation)\n* **Pessimistic:** Prone to **distributed deadlocks** (e.g., Node A locks Record 1 and waits for Record 2 on Node B, while Node B locks Record 2 and waits for Record 1). Detecting and resolving deadlocks across a network is complex and usually relies on aggressive timeouts.\n* **Optimistic:** **Deadlock-free** because transactions do not wait on locks. However, under high contention, OCC suffers from **starvation or livelocks**, where competing nodes repeatedly force each other to abort and retry, causing throughput to collapse (thrashing).\n\n### 5. Throughput and Contention Profile\n* **Pessimistic:** Provides predictable, stable throughput under **high contention**. Even though transactions have to wait in line, work that starts is rarely wasted on rollbacks.\n* **Optimistic:** Provides vastly superior throughput and scalability under **low contention** or read-heavy workloads, because nodes operate independently without waiting on a centralized lock manager.\n\n---\n\n### Summary Comparison\n\n| Feature | Pessimistic Concurrency (PCC) | Optimistic Concurrency (OCC) |\n| :--- | :--- | :--- |\n| **Conflict Detection** | Before data access (Acquire Locks) | At commit time (Validation / Versioning) |\n| **Conflict Resolution** | Block / Wait (or Timeout) | Abort, Rollback, and Retry |\n| **Failure Impact** | Crashed lock-holders block other nodes | Crashed nodes do not block others |\n| **Primary Hazard** | Distributed Deadlocks | Retry storms / Starvation |\n| **Cost of Contention** | High latency (waiting for locks) | Wasted compute & network bandwidth (retries) |\n| **Common Mechanisms** | Distributed 2PL, Leases, Fencing Tokens | Version vectors, MVCC, Compare-And-Swap, ETags |\n\n---\n\n### Real-World Distributed Examples & When to Choose\n\n**Use Pessimistic Concurrency when:**\n* Write contention on specific records (\"hotspots\") is high.\n* The cost of rolling back and retrying a transaction is expensive (e.g., complex multi-step workflows or external side effects).\n* *Examples:* Google Cloud Spanner (uses Two-Phase Locking for read-write transactions), distributed lock services (Redis Redlock, ZooKeeper, etcd) guarding critical sections.\n\n**Use Optimistic Concurrency when:**\n* Workloads are read-heavy and writes rarely collide.\n* Transactions span user \"think time\" or unreliable wide-area networks (where holding locks would paralyze the system).\n* You need maximum horizontal scalability and availability.\n* *Examples:* Microservice APIs using HTTP `ETags` / `If-Match` headers, DynamoDB Conditional Writes, Apache Cassandra Lightweight Transactions (Paxos-based CAS), and conflict-free workflows in Git." }, "raw_response": { "candidates": [ { "content": { "role": "model", "parts": [ { "text": "In distributed systems, concurrency control ensures that multiple nodes or clients can access and modify shared data simultaneously without corrupting it or violating consistency guarantees. \n\nThe fundamental difference between **Pessimistic Concurrency Control (PCC)** and **Optimistic Concurrency Control (OCC)** lies in how they anticipate and handle data conflicts\u2014a challenge that is heavily amplified in distributed environments due to network latency, partial failures, and lack of a global clock.\n\nHere are the key differences between the two approaches in distributed systems:\n\n---\n\n### 1. Core Philosophy & Execution Flow\n* **Pessimistic (PCC):** Assumes conflicts are **likely**. A transaction acquires exclusive or shared locks on the data across the relevant nodes *before* reading or modifying it. Other transactions trying to access the same data are blocked until the lock is released. *(\u201cAsk for permission.\u201d)*\n* **Optimistic (OCC):** Assumes conflicts are **rare**. Transactions execute locally without acquiring locks. They read data (often noting a version number or timestamp), compute changes, and validate at **commit time** whether another node modified the data in the interim. If a conflict is detected, the transaction aborts and retries. *(\u201cAsk for forgiveness.\u201d)*\n\n### 2. Network Overhead and Latency\n* **Pessimistic:** High upfront network overhead. Acquiring and releasing distributed locks requires multiple network round-trips (often using protocols like Two-Phase Locking combined with Two-Phase Commit, or external coordinators like ZooKeeper/etcd) before work can safely finish. Locks are held across network boundaries, extending lock duration due to network latency.\n* **Optimistic:** Low upfront latency. Reads and local computations require minimal coordination. Network coordination only happens during the final validation/commit phase (e.g., via an atomic Compare-And-Swap operation or distributed consensus). However, if a conflict occurs, the entire network cost is wasted and must be repeated.\n\n### 3. Handling Partial Failures and Node Crashes\nIn a distributed system, nodes can crash or experience network partitions at any time.\n* **Pessimistic:** Vulnerable to **blocking on failure**. If a client or coordinator node crashes while holding a distributed lock, that data becomes unavailable to the rest of the cluster until a lease/timeout expires and recovery protocols run.\n* **Optimistic:** Highly resilient to slow or crashing clients. Because no locks are held during the read and compute phases, a crashed client does not block any other nodes in the system from making progress.\n\n### 4. Deadlocks vs. Livelocks (Starvation)\n* **Pessimistic:** Prone to **distributed deadlocks** (e.g., Node A locks Record 1 and waits for Record 2 on Node B, while Node B locks Record 2 and waits for Record 1). Detecting and resolving deadlocks across a network is complex and usually relies on aggressive timeouts.\n* **Optimistic:** **Deadlock-free** because transactions do not wait on locks. However, under high contention, OCC suffers from **starvation or livelocks**, where competing nodes repeatedly force each other to abort and retry, causing throughput to collapse (thrashing).\n\n### 5. Throughput and Contention Profile\n* **Pessimistic:** Provides predictable, stable throughput under **high contention**. Even though transactions have to wait in line, work that starts is rarely wasted on rollbacks.\n* **Optimistic:** Provides vastly superior throughput and scalability under **low contention** or read-heavy workloads, because nodes operate independently without waiting on a centralized lock manager.\n\n---\n\n### Summary Comparison\n\n| Feature | Pessimistic Concurrency (PCC) | Optimistic Concurrency (OCC) |\n| :--- | :--- | :--- |\n| **Conflict Detection** | Before data access (Acquire Locks) | At commit time (Validation / Versioning) |\n| **Conflict Resolution** | Block / Wait (or Timeout) | Abort, Rollback, and Retry |\n| **Failure Impact** | Crashed lock-holders block other nodes | Crashed nodes do not block others |\n| **Primary Hazard** | Distributed Deadlocks | Retry storms / Starvation |\n| **Cost of Contention** | High latency (waiting for locks) | Wasted compute & network bandwidth (retries) |\n| **Common Mechanisms** | Distributed 2PL, Leases, Fencing Tokens | Version vectors, MVCC, Compare-And-Swap, ETags |\n\n---\n\n### Real-World Distributed Examples & When to Choose\n\n**Use Pessimistic Concurrency when:**\n* Write contention on specific records (\"hotspots\") is high.\n* The cost of rolling back and retrying a transaction is expensive (e.g., complex multi-step workflows or external side effects).\n* *Examples:* Google Cloud Spanner (uses Two-Phase Locking for read-write transactions), distributed lock services (Redis Redlock, ZooKeeper, etcd) guarding critical sections.\n\n**Use Optimistic Concurrency when:**\n* Workloads are read-heavy and writes rarely collide.\n* Transactions span user \"think time\" or unreliable wide-area networks (where holding locks would paralyze the system).\n* You need maximum horizontal scalability and availability.\n* *Examples:* Microservice APIs using HTTP `ETags` / `If-Match` headers, DynamoDB Conditional Writes, Apache Cassandra Lightweight Transactions (Paxos-based CAS), and conflict-free workflows in Git.", "thoughtSignature": "AY89a1/7+mSAQqey81jFRefMaQ6AvrZVCY4ca/OurWm/h/1+06QvID7BNzGmb2jXzBAhKl682X8zaGjFvO9QHFoPpdoZHrJkSnSMRQsNeiiKb8L68SCvZ9YHy9yIDMzLLXlIy08htFW9XbwFld2Oyf8/TiRJuOhxdLuLTqW2v9e826fGeWN91THLDPVbT8RzCSIjviADVYfyImWw8NgHZsLZ/8CG1wQFWvf3nQ4dpimrRyHzsnaYm0vnRuVC8fgoqbpvNlpdQiYTEJRl6rB5enwL1SGgxNEJrHGQYMXtpVAogAoemH4YsE0kicxwPRHbzaAlMwOkDAyUkkqxe3tsjbwg372jAnGeX0iHD9sJZ8SZVv92+VJOtnqaSI19cj9mjClTul+lBhjHAvILDdu1bJka271FbjFJFTa/Xx53vy7Xi1adlFT9uM/P9Xm06H/PBXOkDYSVJN23ltVl5KSc19o5nYRYB0mlU1b1onaZST7d+aXRS1uGkmn5wRv+L66iCQcpmwAqpuctJTsYK+ZqLpixT8zc1lTL7yby6w5y6J5f1xq7LNE9dTDjcMI3Ga2/sYKkiCAjrhU2e9VGHay0+d2Q6T6TJVTtGlV4embLrItd4gl2yH67jjNTRL1qF3uQU4aXm9w9q6WbqEkkV6CPS2tXMwgFP7OyJVTvV2iO2RQ+zCXg8UfNA8AiLq1KgdcMR2cjc53rLubTzEs6Gp9Vr+MwOLuzKaOlvJEBixCvS/PNTGXn733S64I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djuZAdhCUzy2RSp7xk9wknenvVr2zTowRV8bjL6i0t0fw3ykvz1QZCqA/3pcSQw5xNXuwJGI8qW7CFqeIpRCJkitUj2jeTO/UmpruC5VYnt+3IH2n5EbbbKG9oFwtjEW1X7Yvt3ErOWr088zQli82YuN5p7vkK9RnEXAQ1BSbHO2SYbYwh8Hid3D/L/Su/Sygse8Gm9EMRhOUfEd0nUtbi92bSmUZstD+yLoJ4MTDp6qZ9Xuc6wl4SH0apH/F14n+kaUX1vBtuBmaCd+6UiGN4sgaM61L35MK0nVMYyos5SgVGqEbRYrIiRmQw8gC7i4n92qorGFuxYDe61kc0pmGmWlU0e/j4QcbF4t8gZK933V93vKTvV7/j93oBQeZ9P0SkyyEKb91Qn9JsEPqLG5hQnMuwShMgyW1muWw2d3cVZnxe7fyladXloDh0DrdiQYgg2T7/283G5u4cSCViLL1WIEQ7JkxCFvnJzJS0E/rInqZ3r1PRY2xOxSmtMGWF5mZTjpQKclKpLx8NtAytTj3tkMIZ3q2RFoLeQN/sdX0Fyfr5G8vCyfonmV3A8cBLoD+hls9yFt+gkwJh+XSCAOzN2HYFGSnKawIg8Ssdsgk9jPMXwb/wiC+/qKaHJll4+eH+VAkiwm+cS+/JMD0P2h15mVzbzccnhDG8grixEiALF9HsX6rVQtYCMGTjuKYBPFrPmSsyjXRo022JQI6j3bsuMsgNE5ojog6L/zNeDEYIaLHkBPSD45mvVgEcorw9enBhklgS8398aAMaFciFSTKI6Q2OkLETBRKdBen8zvFD08gZ/vRMzZS55bs69waAC9toIMMRMysBCOp5A3U4P/DqYtCVPM0hySHLk8Q6otJvyqrCHUgXOIpN4Zf+vSIFgbowtuQ==" } ] }, "finishReason": "STOP" } ], "usageMetadata": { "promptTokenCount": 46, "candidatesTokenCount": 1141, "totalTokenCount": 1812, "trafficType": "ON_DEMAND", "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 46 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 1141 } ], "thoughtsTokenCount": 625 }, "modelVersion": "gemini-4-carbon", "createTime": "2026-11-10T15:52:57.957068Z", "responseId": "2T3zaoy1OoWNu-gPi6rbmQQ" }, "code_snippets": [ { "label": "typescript", "language": "typescript", "code": "const response = await env.AI.run(\n 'google/gemini-4-carbon',\n {\n contents: [\n {\n parts: [\n {\n text: 'What are the key differences between optimistic and pessimistic concurrency control in distributed systems?',\n },\n ],\n role: 'user',\n },\n ],\n },\n)\nconsole.log(response)" }, { "label": "curl", "language": "bash", "code": "curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \\\n --header \"Authorization: Bearer $CLOUDFLARE_API_TOKEN\" \\\n --header \"Content-Type: application/json\" \\\n --data '{\n \"model\": \"google/gemini-4-carbon\",\n \"input\": {\n \"contents\": [\n {\n \"parts\": [\n {\n \"text\": \"What are the key differences between optimistic and pessimistic concurrency control in distributed systems?\"\n }\n ],\n \"role\": \"user\"\n }\n ]\n }\n}'" } ] }, { "name": "Agentic Coding", "description": "Coding task with a system instruction", "input": { "contents": [ { "parts": [ { "text": "Write a Python function that merges two sorted lists into one sorted list." } ], "role": "user" } ], "systemInstruction": { "parts": [ { "text": "You are an expert software engineering agent. Write concise, correct, well-documented code." } ] } }, "output": { "text": "Here is a concise, efficient implementation using the classic two-pointer approach, which runs in $O(n + m)$ time and $O(n + m)$ space:\n\n```python\nfrom typing import TypeVar\n\nT = TypeVar(\"T\")\n\n\ndef merge_sorted_lists(list1: list[T], list2: list[T]) -> list[T]:\n \"\"\"Merges two sorted lists into a single sorted list.\n\n Args:\n list1: The first sorted list.\n list2: The second sorted list.\n\n Returns:\n A new sorted list containing all elements from both input lists.\n \"\"\"\n merged: list[T] = []\n i, j = 0, 0\n len1, len2 = len(list1), len(list2)\n\n # Compare elements from both lists and append the smaller one\n while i < len1 and j < len2:\n if list1[i] <= list2[j]: # type: ignore[operator]\n merged.append(list1[i])\n i += 1\n else:\n merged.append(list2[j])\n j += 1\n\n # Append any remaining elements (only one of these slices will be non-empty)\n merged.extend(list1[i:])\n merged.extend(list2[j:])\n\n return merged\n```\n\n### Example Usage\n\n```python\na = [1, 3, 5, 7]\nb = [2, 3, 6, 8, 9]\n\nprint(merge_sorted_lists(a, b))\n# Output: [1, 2, 3, 3, 5, 6, 7, 8, 9]\n```\n\n### Pythonic Alternative (`heapq.merge`)\nIn production code, you can also use Python's standard library `heapq.merge`, which is implemented in C, works on any sorted iterable, and evaluates lazily:\n\n```python\nimport heapq\n\nmerged = list(heapq.merge(list1, list2))\n```" }, "raw_response": { "candidates": [ { "content": { "role": "model", "parts": [ { "text": "Here is a concise, efficient implementation using the classic two-pointer approach, which runs in $O(n + m)$ time and $O(n + m)$ space:\n\n```python\nfrom typing import TypeVar\n\nT = TypeVar(\"T\")\n\n\ndef merge_sorted_lists(list1: list[T], list2: list[T]) -> list[T]:\n \"\"\"Merges two sorted lists into a single sorted list.\n\n Args:\n list1: The first sorted list.\n list2: The second sorted list.\n\n Returns:\n A new sorted list containing all elements from both input lists.\n \"\"\"\n merged: list[T] = []\n i, j = 0, 0\n len1, len2 = len(list1), len(list2)\n\n # Compare elements from both lists and append the smaller one\n while i < len1 and j < len2:\n if list1[i] <= list2[j]: # type: ignore[operator]\n merged.append(list1[i])\n i += 1\n else:\n merged.append(list2[j])\n j += 1\n\n # Append any remaining elements (only one of these slices will be non-empty)\n merged.extend(list1[i:])\n merged.extend(list2[j:])\n\n return merged\n```\n\n### Example Usage\n\n```python\na = [1, 3, 5, 7]\nb = [2, 3, 6, 8, 9]\n\nprint(merge_sorted_lists(a, b))\n# Output: [1, 2, 3, 3, 5, 6, 7, 8, 9]\n```\n\n### Pythonic Alternative (`heapq.merge`)\nIn production code, you can also use Python's standard library `heapq.merge`, which is implemented in C, works on any sorted iterable, and evaluates lazily:\n\n```python\nimport heapq\n\nmerged = list(heapq.merge(list1, list2))\n```", "thoughtSignature": "AY89a19L81xxk8WZs3fRP6B8Vv2bXwZTmLS7bcqOzt2sFi46/NZNaY0wQLL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0i4Io+YByl2TziEGpGqPLA8BN+1qfNkLjzCkDqdQsm+RMXTbb/J+q/S/fFTihhRrmSckxHkc1GkTnJ1j/aCxH694kvoB6OoEhHU7ZqlPx0q1z5R4BRrT8wZ8ZvZnO00xMzkGLwtKBEU0w49XwOAnCfU/JVzLpalCbZbOykUJWni/QqJp0V77SS7R8OYKZePbl1LZP+RTKhKSICnl7BBuJ/CoqKE3159DjXr9B+k/7arz/ls1jx9VF9+lQ8wWwvyloT4qGs4FgNlQcwtYRaRQB0cId0U90bOg2HLrhj/s5/kUZIo43gd/GQR6XTT1K8vjNuSX+OdkqZfj7YPu2OjO6RX0OXQ2RIUfnWnn0xZ74/kdnguAGpUwEMFxyBvwd2y2veWxpNw9j5qpTD29/C4KeOtVl0T62NdnX0+jaoNWT1qVzDSsGtqueKm4hXF5J0CKyuW7waEnH4sinAvph55vCu1mgOE4ZsdU8P4AeYZdl4NiKG+jJjE0RVASl8y7QUIQbzGjf/XnaDQIxse9UJJIBYbP7eYS1XZebKCPRbS9L/blPEWL2AUYZe1e4Wn2yIZ861yV8YmWgpkAawtI2cZrI5AnB5pStZ47iJse3ZWsdY569JGf4tfIZXq78C52T3t4qfIMsbxENLNmmpmIMUdO6rzFtXhP930g7QPAhd3F17RSnm/OOs01cJ7KQdB5VbuzwCr1wl++qTxDOdZ3EF3zJ2krCU4duHXNmHkxTaulJsfzNjwwQMglC9P9qVAj/MXyl6QEfZlTTkdQXwoX+kr8PilWGtyqEUJz1c9F5YWY5El8Bj0icZEugQg2ry8itIkd39CzYJZ98Iea0FwjGbtbEBofOMIhR4xZYlcseF4wPoT32TrFSZVqlHJZ8yThaM=" } ] }, "finishReason": "STOP" } ], "usageMetadata": { "promptTokenCount": 68, "candidatesTokenCount": 472, "totalTokenCount": 956, "trafficType": "ON_DEMAND", "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 68 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 472 } ], "thoughtsTokenCount": 416 }, "modelVersion": "gemini-4-carbon", "createTime": "2026-11-10T15:53:24.940732Z", "responseId": "9D3zary1OZe4u-gPsOO98AY" }, "code_snippets": [ { "label": "typescript", "language": "typescript", "code": "const response = await env.AI.run(\n 'google/gemini-4-carbon',\n {\n contents: [\n {\n parts: [\n { text: 'Write a Python function that merges two sorted lists into one sorted list.' },\n ],\n role: 'user',\n },\n ],\n systemInstruction: {\n parts: [\n {\n text: 'You are an expert software engineering agent. Write concise, correct, well-documented code.',\n },\n ],\n },\n },\n)\nconsole.log(response)" }, { "label": "curl", "language": "bash", "code": "curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \\\n --header \"Authorization: Bearer $CLOUDFLARE_API_TOKEN\" \\\n --header \"Content-Type: application/json\" \\\n --data '{\n \"model\": \"google/gemini-4-carbon\",\n \"input\": {\n \"contents\": [\n {\n \"parts\": [\n {\n \"text\": \"Write a Python function that merges two sorted lists into one sorted list.\"\n }\n ],\n \"role\": \"user\"\n }\n ],\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are an expert software engineering agent. Write concise, correct, well-documented code.\"\n }\n ]\n }\n }\n}'" } ] }, { "name": "Multi-turn Conversation", "description": "Continuing a multi-step coding conversation, typical of an agentic loop", "input": { "contents": [ { "parts": [ { "text": "I have a bug where my recursive fibonacci function is too slow for n=40." } ], "role": "user" }, { "parts": [ { "text": "That's expected with naive recursion since it recomputes overlapping subproblems exponentially. You can fix it with memoization or an iterative approach. Which would you like to see?" } ], "role": "model" }, { "parts": [ { "text": "Show me the memoized version." } ], "role": "user" } ] }, "output": { "text": "Since you didn't mention a specific language, here is how to do it in **Python** (the logic translates easily to any language).\n\nMemoization works by storing the results of expensive function calls in a dictionary/hash map so you only calculate each Fibonacci number once. This drops the time complexity from $O(2^n)$ down to $O(n)$, making `n=40` run instantaneously.\n\n### 1. Manual Memoization (Works in any language)\nYou pass a `memo` dictionary down through the recursive calls to keep track of values you've already solved:\n\n```python\ndef fib(n, memo=None):\n if memo is None:\n memo = {}\n\n # 1. Check if we already calculated this value\n if n in memo:\n return memo[n]\n\n # 2. Base cases\n if n <= 1:\n return n\n\n # 3. Calculate, store in memo, and return\n memo[n] = fib(n - 1, memo) + fib(n - 2, memo)\n return memo[n]\n\n\nprint(fib(40)) # Outputs: 102334155 instantly\n```\n\n*(Note: We use `memo=None` as the default argument instead of `memo={}` to avoid Python's mutable default argument quirk, though `memo={}` would technically work as a persistent cache here.)*\n\n### 2. Using Built-in Caching (Python-specific)\nIf you happen to be using Python 3.9+, the standard library has a decorator that does this exact thing automatically:\n\n```python\nfrom functools import cache\n\n\n@cache\ndef fib(n):\n if n <= 1:\n return n\n return fib(n - 1) + fib(n - 2)\n\n\nprint(fib(40))\n```\n*(For Python 3.2\u20133.8, you can use `@lru_cache(maxsize=None)` from `functools` instead).*\n\n---\n\nIf you are using JavaScript, Java, C++, or another language, let me know and I'll write out the syntax for that one!" }, "raw_response": { "candidates": [ { "content": { "role": "model", "parts": [ { "text": "Since you didn't mention a specific language, here is how to do it in **Python** (the logic translates easily to any language).\n\nMemoization works by storing the results of expensive function calls in a dictionary/hash map so you only calculate each Fibonacci number once. This drops the time complexity from $O(2^n)$ down to $O(n)$, making `n=40` run instantaneously.\n\n### 1. Manual Memoization (Works in any language)\nYou pass a `memo` dictionary down through the recursive calls to keep track of values you've already solved:\n\n```python\ndef fib(n, memo=None):\n if memo is None:\n memo = {}\n\n # 1. Check if we already calculated this value\n if n in memo:\n return memo[n]\n\n # 2. Base cases\n if n <= 1:\n return n\n\n # 3. Calculate, store in memo, and return\n memo[n] = fib(n - 1, memo) + fib(n - 2, memo)\n return memo[n]\n\n\nprint(fib(40)) # Outputs: 102334155 instantly\n```\n\n*(Note: We use `memo=None` as the default argument instead of `memo={}` to avoid Python's mutable default argument quirk, though `memo={}` would technically work as a persistent cache here.)*\n\n### 2. Using Built-in Caching (Python-specific)\nIf you happen to be using Python 3.9+, the standard library has a decorator that does this exact thing automatically:\n\n```python\nfrom functools import cache\n\n\n@cache\ndef fib(n):\n if n <= 1:\n return n\n return fib(n - 1) + fib(n - 2)\n\n\nprint(fib(40))\n```\n*(For Python 3.2\u20133.8, you can use `@lru_cache(maxsize=None)` from `functools` instead).*\n\n---\n\nIf you are using JavaScript, Java, C++, or another language, let me know and I'll write out the syntax for that one!", "thoughtSignature": "AY89a1/czByhhcPnon5/MC4FSJQ8GHuoTWKShjS9Em2sttH6EB8BXix7r1Xp2k4Owso5MLW2N8QKgwdIc9VpWhFW/fKC/kZ3248r+DCQazHh0/BGYC6OorTbdrkaqc4k4RNK7TmeBN+bb++TB5BNP5Z68NHmjP4yosWEXWgAxpgLLYxJilodMjHFsuGobF+IHd3HdK6W9rXsiPELo2FeX+ovsl9wqMkpUIaoZUanym8UuT5HqYY9TNgcbu+AeCGSD69epkpv0pi6xTA2vPdDNuq3Etc9j3aRp1uU17yn/xOT9XL1fH+zHo7jL+siWVMiGVbcOFL7B6K5HApfnD+7OJ3yK0cF4SKSLFWWrFoGeneXsNk9p2/s2B6qQgtR1DHGZ0Bueol/iuM3WbfTbLDbJyZokqUQrEXz7uNIL+gkNBEAVmTqsTkQ32uxiLGQXJiEAKiTN5TPsMJyP+rzVdk/61W4d9EB4cTtTfZP0VzAHDsDutv2ZiHAW2Q+nKK4pJ/mjMp7xsDIFp4seDdXJBXbAqZD/vtTMsSFWRoeYTvwAXjZGFbkjpV/lBoqB1rAEH3FkmSpvNz5i2Wi3IbwLsZrNc5rZ/DNmnpGc/75gVnjlqs1MSGIMBKSr3ITVwM+w8xBE5lJcXYCw7BzMXg7bG4KOYzCkBpl0w5nwuUIpqfRY85uYjMM1VjHsQpz6OqRNzYPhqYliVvDGNJ26e8lcltuIUofUN9cZCBNKjm+9kxu+fuFqGuoU6QtnrFE33MnHdn3m09kOoDmby1qdCmqqonj0P8Zyl16YVQNWNZHtOdoL6k8FDpflrb7vmEjMsB2XVtUiRjPzWHg50laJ0l6/Xj3lNc/MXsAUG+0dBSAST27bwh6hn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1JIKxuJoflKKDXNKA2PXk3+/wVYFxM7pk9zPRC2MbokrdzLIIBAiM6nND+FG/qrbn9ST9UBMp4RORYorVdxiXNrGJyc+UXL7We9GLVqwDTfUTSI5q3FXtDiwTv7hZOnH9+zk38CinbDc7XGpH0Efnw0pIRILIvbTzC6Xq3n/GeUKjYOYdispJXEi0Q+RPrnSITxoWfNp9dUgcMsdORTRGbnhSq3teTjtRrH8kCkKDDD87tl/i+WlQ53D8rTpCQKS0fCYFHKl9UmJDOTPZpNk8JrluVjmKPHNKuWJ9T4ZVpTjRQ4KCZ7C9OjYr9k2ROBUN4dK/9CYgOiAKT3nWJoJ2tt1gOWoliyg9G85EbMItaOUNO+GRy61Jp3Y6gE1dD1JYZSIUof9ZpeDefMqno1TLHWqLCbfQoTVG4F+GNPdImWVrbUJnqmVjJ+Kuy5e5nqp6USwqrOj3MMrJ1JquCUGeSDSuq/pEzEijYaaRoX8+Hlj6TZAwxLrM2gn1RivDopl1uDcUW/+19s0/zsr/lYMw5kyToQJpFVMKp0jC/ZbmvFQT5S5ggCihLoEEYQyJSj2ogfBvJ4hH+oWvyHTSBGbNvNlZ67g5Fa+KmaiO04EJ0qGSE5Kp6EzKL4mZhXZTb3b66jaeCpPYiJEdtWDU8oTw+loVgm1bmxuwG235EOLkq4dNiDz9rSZT4jp3OrUGrnF/KQvu7JloxNBnPLb5CVhVDU2VAnAL8Khhg0G7C6Q6UzH61UjwaIZTdwmVDIyqVhm8kDyRscOHVfeRHd7PPwh94dwrdjuArLEAAkBybDz1Le1JzZm5ZckABbCsbzgIaTwqgQQGrAUVqLmRnnk4S0KI3b15Y5iPICvG85vng==" } ] }, "finishReason": "STOP" } ], "usageMetadata": { "promptTokenCount": 101, "candidatesTokenCount": 481, "totalTokenCount": 1090, "trafficType": "ON_DEMAND", "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 101 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 481 } ], "thoughtsTokenCount": 508 }, "modelVersion": "gemini-4-carbon", "createTime": "2026-11-10T15:53:39.705154Z", "responseId": "Az7zaoKFK4jIu-gPuKPXmQo" }, "code_snippets": [ { "label": "typescript", "language": "typescript", "code": "const response = await env.AI.run(\n 'google/gemini-4-carbon',\n {\n contents: [\n {\n parts: [{ text: 'I have a bug where my recursive fibonacci function is too slow for n=40.' }],\n role: 'user',\n },\n {\n parts: [\n {\n text: \"That's expected with naive recursion since it recomputes overlapping subproblems exponentially. You can fix it with memoization or an iterative approach. Which would you like to see?\",\n },\n ],\n role: 'model',\n },\n { parts: [{ text: 'Show me the memoized version.' }], role: 'user' },\n ],\n },\n)\nconsole.log(response)" }, { "label": "curl", "language": "bash", "code": "curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \\\n --header \"Authorization: Bearer $CLOUDFLARE_API_TOKEN\" \\\n --header \"Content-Type: application/json\" \\\n --data '{\n \"model\": \"google/gemini-4-carbon\",\n \"input\": {\n \"contents\": [\n {\n \"parts\": [\n {\n \"text\": \"I have a bug where my recursive fibonacci function is too slow for n=40.\"\n }\n ],\n \"role\": \"user\"\n },\n {\n \"parts\": [\n {\n \"text\": \"That'\\''s expected with naive recursion since it recomputes overlapping subproblems exponentially. You can fix it with memoization or an iterative approach. Which would you like to see?\"\n }\n ],\n \"role\": \"model\"\n },\n {\n \"parts\": [\n {\n \"text\": \"Show me the memoized version.\"\n }\n ],\n \"role\": \"user\"\n }\n ]\n }\n}'" } ] }, { "name": "Spatial Reasoning", "description": "A reasoning-heavy puzzle with the thinking level set to HIGH", "input": { "contents": [ { "parts": [ { "text": "A cube is painted red on all faces, then cut into 27 equal smaller cubes. How many of the smaller cubes have exactly two red faces?" } ], "role": "user" } ], "generationConfig": { "thinkingConfig": { "thinkingLevel": "HIGH" } } }, "output": { "text": "There are **12** smaller cubes that have exactly two red faces.\n\n**Here is why:**\nSince the large cube is cut into 27 equal smaller cubes, it is divided into a $3 \\times 3 \\times 3$ grid ($\\sqrt[3]{27} = 3$). You can figure out how many faces are painted based on where each smaller cube was located in the original large cube:\n\n* **3 red faces (Corners):** A cube has 8 corners, so there are **8** of these cubes.\n* **2 red faces (Edges):** The cubes with two painted faces are located along the edges, *between* the corners. A cube has 12 edges, and in a $3 \\times 3 \\times 3$ grid, there is 1 middle cube per edge ($12 \\times 1 = \\mathbf{12}$). \n* **1 red face (Centers of each face):** A cube has 6 faces, with 1 cube right in the center of each face, giving **6** of these cubes.\n* **0 red faces (Core):** There is **1** cube completely hidden in the very center of the $3 \\times 3 \\times 3$ grid with no paint at all.\n\n*(Check: $8 + 12 + 6 + 1 = 27$ total cubes)*" }, "raw_response": { "candidates": [ { "content": { "role": "model", "parts": [ { "text": "There are **12** smaller cubes that have exactly two red faces.\n\n**Here is why:**\nSince the large cube is cut into 27 equal smaller cubes, it is divided into a $3 \\times 3 \\times 3$ grid ($\\sqrt[3]{27} = 3$). You can figure out how many faces are painted based on where each smaller cube was located in the original large cube:\n\n* **3 red faces (Corners):** A cube has 8 corners, so there are **8** of these cubes.\n* **2 red faces (Edges):** The cubes with two painted faces are located along the edges, *between* the corners. A cube has 12 edges, and in a $3 \\times 3 \\times 3$ grid, there is 1 middle cube per edge ($12 \\times 1 = \\mathbf{12}$). \n* **1 red face (Centers of each face):** A cube has 6 faces, with 1 cube right in the center of each face, giving **6** of these cubes.\n* **0 red faces (Core):** There is **1** cube completely hidden in the very center of the $3 \\times 3 \\times 3$ grid with no paint at all.\n\n*(Check: $8 + 12 + 6 + 1 = 27$ total cubes)*", "thoughtSignature": "AY89a1/ZMXQ0mbL4K6MLfpWo1nrnnkqoqmTrYN5o5YlCMNGHOFaDq+1U7ziC/4D0QJwWdRSIjkhn05UZLedtMl7UlQNe3Zkb9vGpmgHkpMBosWrLKfMJaD4wqSv1+elVVnQ3KVCgzhFa8dWDl0t9mVwzqpRkrgwP1SRpJlOY+ENWDUbxYNwXuYMed8bexwGRppr1ayhsESrhXe0S8gqyKufp3fon1OYhvG6E9XTFJ8Z4h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+QwquJmrTXaPmDkyeaPHBSL0+fTY374huOuDbq2gNUGrksIlyIMxzK/pulxre159abShl3cnD9lE+7zDBTSQoAE1AKDAn/qgVhg96NFFK/lKy8g2xBlRs1djP5vh+qOPF2FGG2c4/otIBc8lxpB4TeR7W+qqfpvTErJdV/slE/dlihEui1piUUkwSOcsmG8hkNvI0pqsYnMGiEeG7ZkUYKomKuoGpB8EpBRUsmDrbBn7MEQUD2zQR90Z6EMImrvAOV4/R8OUH2jOn089nIiMMQfu0CHrsM+odXWHDDvsnmT8C2KnMIcGwG5MkVu9cRGZfEYYCsKxrEuRFGnwzmiGf/zmKvlT//4kZxj5/O2rXHSzl+y/3QN278MY9XrZxa2qf7tMpj4/mOPqJe1m3Ijyf43l30UuMCl+hYwqHiAU6Reg870gCbC6LiSQ4W/4M7XsQ9hW5ICJ6Y0xHeGNpWxvsAk0ytFcPbClyIdwnQ3Ce9gQpFzu++6gtFWIH10Mgs9IWbPOci0Sg3cyCSJv1bUabn1O8FUD6YJsc3hUvfPd7Eyo+yutyh8da/pJaEaGwHbVj+79rJmVe2I4dy5SVvg9ne/laJiEPceZBopFCyIwOjobFRgZ9ksF8pAtTdl5qG1InzHMZNIerW2NpfkcUJz3RKMbtkj2mlUAcb6/HyyXBzwqeSvAQAVoSuGaZ2k+7lz6cH4AfipfdCsIhNzpsWTD6Z6FDqI=" } ] }, "finishReason": "STOP" } ], "usageMetadata": { "promptTokenCount": 62, "candidatesTokenCount": 297, "totalTokenCount": 1077, "trafficType": "ON_DEMAND", "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 62 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 297 } ], "thoughtsTokenCount": 718 }, "modelVersion": "gemini-4-carbon", "createTime": "2026-11-10T15:53:55.521592Z", "responseId": "Ez7zavjqH7_Xu-gPx6arkQM" }, "code_snippets": [ { "label": "typescript", "language": "typescript", "code": "const response = await env.AI.run(\n 'google/gemini-4-carbon',\n {\n contents: [\n {\n parts: [\n {\n text: 'A cube is painted red on all faces, then cut into 27 equal smaller cubes. How many of the smaller cubes have exactly two red faces?',\n },\n ],\n role: 'user',\n },\n ],\n generationConfig: { thinkingConfig: { thinkingLevel: 'HIGH' } },\n },\n)\nconsole.log(response)" }, { "label": "curl", "language": "bash", "code": "curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \\\n --header \"Authorization: Bearer $CLOUDFLARE_API_TOKEN\" \\\n --header \"Content-Type: application/json\" \\\n --data '{\n \"model\": \"google/gemini-4-carbon\",\n \"input\": {\n \"contents\": [\n {\n \"parts\": [\n {\n \"text\": \"A cube is painted red on all faces, then cut into 27 equal smaller cubes. How many of the smaller cubes have exactly two red faces?\"\n }\n ],\n \"role\": \"user\"\n }\n ],\n \"generationConfig\": {\n \"thinkingConfig\": {\n \"thinkingLevel\": \"HIGH\"\n }\n }\n }\n}'" } ] } ], "default_example": null, "code_snippets": [], "supports_async": false, "zdr": true, "zdr_comment": null, "external_info": "https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/4-carbon", "terms": "https://ai.google.dev/gemini-api/terms", "cover_image_url": null, "metadata": { "Default thinking level": "medium", "Output per request": "65,536 tokens (up to 1,048,576 with long decodes)" }, "request_formats": [ "chat-completions" ], "provider_id": "google", "providers": null, "provider_details": [ { "id": "google-vertex-ai", "pricing": { "input_tokens": 2, "output_tokens": 10, "input_cached_tokens": 0.1 } } ], "model_providers": [ { "provider": "google-vertex-ai", "ordinal": 0, "pricing": null } ], "banner": null, "pinned": false, "created_at": "2026-11-11 15:07:52", "schema": { "input": { "$schema": "https://json-schema.org/draft/2020-12/schema", "oneOf": [ { "type": "object", "properties": { "contents": { "type": "array", "items": { "type": "object", "properties": { "role": { "type": "string", "enum": [ "user", "model" ] }, "parts": { "type": "array", "items": { "type": "object", "properties": { "text": { "type": "string" } }, "additionalProperties": {} } } }, "required": [ "parts" ], "additionalProperties": {} } }, "systemInstruction": { "type": "object", "properties": { "parts": { "type": "array", "items": { "type": "object", "properties": { "text": { "type": "string" } }, "additionalProperties": {} } } }, "required": [ "parts" ], "additionalProperties": {} }, "generationConfig": { "type": "object", "properties": { "temperature": { "type": "number" }, "topP": { "type": "number" }, "topK": { "type": "number" }, "maxOutputTokens": { "type": "number" }, "candidateCount": { "type": "number" }, "stopSequences": { "type": "array", "items": { "type": "string" } }, "responseMimeType": { "type": "string" } }, "additionalProperties": {} }, "safetySettings": { "type": "array", "items": { "type": "object", "properties": { "category": { "type": "string" }, "threshold": { "type": "string" } }, "required": [ "category", "threshold" ], "additionalProperties": {} } }, "tools": { "type": "array", "items": {} }, "toolConfig": {} }, "required": [ "contents" ], "additionalProperties": {}, "title": "Generate Content" }, { "type": "object", "properties": { "messages": { "type": "array", "items": { "type": "object", "properties": { "role": { "type": "string", "enum": [ "system", "developer", "user", "assistant", "tool" ] }, "content": { "anyOf": [ { "type": "string" }, { "type": "null" }, { "type": "array", "items": {} } ] } }, "required": [ "role" ], "additionalProperties": {} } }, "temperature": { "type": "number", "minimum": 0, "maximum": 2 }, "max_tokens": { "type": "number", "exclusiveMinimum": 0 }, "max_completion_tokens": { "type": "number", "exclusiveMinimum": 0 }, "top_p": { "type": "number", "minimum": 0, "maximum": 1 }, "frequency_penalty": { "type": "number", "minimum": -2, "maximum": 2 }, "presence_penalty": { "type": "number", "minimum": -2, "maximum": 2 }, "stream": { "type": "boolean" }, "stream_options": { "type": "object", "properties": { "include_usage": { "type": "boolean" } }, "additionalProperties": false }, "tools": { "type": "array", "items": {} }, "tool_choice": {}, "response_format": {}, "modalities": { "type": "array", "items": { "type": "string", "enum": [ "text", "audio" ] } }, "audio": { "type": "object", "properties": { "voice": { "type": "string", "enum": [ "alloy", "ash", "ballad", "coral", "echo", "sage", "shimmer", "verse" ] }, "format": { "type": "string", "enum": [ "wav", "mp3", "flac", "opus", "pcm16" ] } }, "additionalProperties": false }, "reasoning_effort": { "description": "Optional reasoning control; availability and accepted values are model-dependent.", "type": [ "string", "null" ] } }, "required": [ "messages" ], "additionalProperties": {}, "title": "Chat Completions" } ] }, "output": { "$schema": "https://json-schema.org/draft/2020-12/schema", "oneOf": [ { "type": "object", "properties": { "candidates": { "type": "array", "items": {} }, "usageMetadata": { "type": "object", "properties": { "promptTokenCount": { "type": "number" }, "candidatesTokenCount": { "type": "number" }, "totalTokenCount": { "type": "number" } }, "additionalProperties": {} }, "modelVersion": { "type": "string" } }, "additionalProperties": {}, "title": "Generate Content" }, { "type": "object", "properties": { "id": { "type": "string" }, "object": { "type": "string" }, "created": { "type": "number" }, "model": { "type": "string" }, "choices": { "type": "array", "items": { "type": "object", "properties": { "index": { "type": "number" }, "message": { "type": "object", "properties": { "role": { "type": "string" }, "content": { "type": [ "string", "null" ] }, "tool_calls": { "anyOf": [ { "type": "array", "items": {} }, { "type": "null" } ] }, "audio": { "anyOf": [ { "type": "object", "properties": { "id": { "type": "string" }, "data": { "type": "string" }, "expires_at": { "type": "number" }, "transcript": { "type": "string" } }, "additionalProperties": {} }, { "type": "null" } ] } }, "required": [ "role" ], "additionalProperties": {} }, "finish_reason": { "type": [ "string", "null" ] } }, "required": [ "index", "message", "finish_reason" ], "additionalProperties": {} } }, "usage": { "type": "object", "properties": { "prompt_tokens": { "type": "number" }, "completion_tokens": { "type": "number" }, "total_tokens": { "type": "number" } }, "required": [ "prompt_tokens", "completion_tokens", "total_tokens" ], "additionalProperties": {} } }, "required": [ "id", "object", "created", "model", "choices" ], "additionalProperties": {}, "title": "Chat Completions" } ] } } }