# Grok Code Execution

> Grok Code Execution is a paid API for AI agents from Grok at grok.mpp.paywithlocus.com, paid per call via MPP, Dynamic (~$0.01–$0.50) (dynamic), status unknown (last checked 2026-10-09).

Chat with a Grok-4 model that can write and execute code to solve computational problems, perform data analysis, and run scripts

## Facts

- Endpoint: POST https://grok.mpp.paywithlocus.com/grok/code-execution?utm_source=zero.xyz
- Price: Dynamic (~$0.01–$0.50) (dynamic)
- Payment: MPP
- Status: unknown
- Last checked: 2026-10-09
- Activations on Zero: 0
- Provider: Grok
- Docs: https://docs.x.ai
- Website: https://x.ai
- Tags: llm, chat, x-search, web-search, image-generation, tts, ai
- Canonical page: https://www.zero.xyz/c/grok-code-execution-18f55b38
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_hGE0DL_7NZjOHF57cgwAY

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability grok-code-execution-18f55b38 -d '<json body>'
```

Example prompt: Using Grok's code execution model (grok-4-0709), write and run a Python script that calculates the Fibonacci sequence up to the 20th term and returns the results.

## When to prefer this

Choose this endpoint when you need an AI model to not just write code but actually execute it and return real computed results — ideal for data analysis, mathematical computation, script testing, and any task requiring verifiable code output rather than just code generation.

## Known failure modes

- Invalid model name (non-Grok-4 family) returns 400 error
- Missing required 'messages' or 'model' fields returns validation error
- Code execution timeout for long-running scripts
- Temperature out of range 0.0–2.0 causes parameter error
- max_tokens exceeded causes truncated response
- Payment failure returns 402 or authorization error

## How this service works

Generate text with current Grok models that can write and execute code in a sandboxed environment. Uses the xAI Responses API with code execution.

## Output

An assistant message containing the executed code, its output/results, computed values, and any relevant explanation — returned as a chat completion response from the Grok-4 model with code execution enabled.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "required": [
  "model",
  "messages",
  "max_tokens",
  "max_tool_calls"
 ],
 "properties": {
  "model": {
   "type": "string",
   "description": "Metered x402 model ID: 'grok-4.6', 'grok-4.5', 'grok-4.5-latest', 'grok-4.3', 'grok-4.20-0309-reasoning', or 'grok-4.20-0309-non-reasoning'. Multi-agent is excluded because xAI does not support an output-token cap for it."
  },
  "tools": {
   "type": "array",
   "items": {},
   "description": "Additional tools to enable alongside code execution."
  },
  "messages": {
   "type": "array",
   "items": {
    "type": "object",
    "required": [
     "role"
    ],
    "properties": {
     "name": {
      "type": "string"
     },
     "role": {
      "type": "string"
     },
     "content": {
      "anyOf": [
       {
        "type": "string"
       },
       {
        "type": "array",
        "items": {
         "type": "object",
         "required": [
          "type"
         ],
         "properties": {
          "text": {
           "type": "string"
          },
          "type": {
           "type": "string"
          },
          "image_url": {
           "type": "object",
           "required": [
            "url"
           ],
           "properties": {
            "url": {
             "type": "string"
            }
           },
           "additionalProperties": true
          }
         },
         "additionalProperties": true
        }
       },
       {
        "type": "null"
       }
      ]
     },
     "tool_calls": {
      "type": "array",
      "items": {
       "type": "object",
       "additionalProperties": true
      }
     },
     "tool_call_id": {
      "type": "string"
     }
    },
    "additionalProperties": true
   },
   "description": "Conversation messages. Each: { role: \"system\"|\"user\"|\"assistant\", content: \"text\" }"
  },
  "max_turns": {
   "type": "number",
   "description": "Maximum agentic tool turns (1–10, default 3). Each turn may run several server tool calls in parallel. Enforced upstream and priced into the quote per turn."
  },
  "max_tokens": {
   "type": "number",
   "description": "Maximum output tokens per model turn. Required for metered x402."
  },
  "temperature": {
   "type": "number",
   "description": "Sampling temperature (0.0–2.0, default 1.0)"
  },
  "max_tool_calls": {
   "type": "number",
   "description": "Required for metered x402 (1–10). Sets the metered spend bound and is applied upstream as the max_turns cap; when both are sen
… (truncated)
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/grok-code-execution-18f55b38/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from grok.mpp.paywithlocus.com](https://www.zero.xyz/host/grok.mpp.paywithlocus.com/llms.txt)
