# Grok Code Execution via Locus x402

> Grok Code Execution via Locus x402 is a paid API for AI agents from grok.x402.paywithlocus.com, paid per call via x402, $0.001/call, status unknown (last checked 2026-09-13).

Run code via xAI Grok models with sandboxed code execution enabled, billed per call over the x402 micropayment protocol.

## Facts

- Endpoint: POST https://grok.x402.paywithlocus.com/grok/code-execution
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-13
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/grok-code-execution-via-locus-x402-83eb43d3
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_vnOu6-7BwCNebywAFkkGJ

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-via-locus-x402-83eb43d3 -d '<json body>'
```

Example prompt: Use Grok grok-4.5 with code execution enabled to figure out the first 20 Fibonacci numbers — run the code and show me the output, keep it to 512 output tokens and no more than 3 tool calls.

## When to prefer this

Choose this endpoint when you need an AI model to not only generate code but actually execute it in a sandboxed environment and return the output — ideal for data analysis, numerical computation, debugging, or any task where running code is necessary to produce a verified answer. Prefer it over a plain chat endpoint when correctness requires execution, not just generation. The x402 micropayment model makes it suitable for pay-per-call agent workflows without subscription overhead.

## Known failure modes

- Invalid or unsupported model ID returns an error — only specific metered model IDs like 'grok-4.5' are accepted
- Exceeding max_tool_calls cap causes the server to halt further tool invocations
- Missing max_tokens causes request rejection since it is required for metered x402 billing
- Payment failure or insufficient USDC balance results in a 402 Payment Required response
- Code execution sandbox timeout if the executed code runs too long
- Malformed messages array (wrong roles or structure) causes a validation error

## How this service works

xAI models — chat, web/X search, code execution, image generation/editing, and text-to-speech.

## Output

Returns a JSON object with a 'data' field containing the model's response (including code execution output), a 'payment' field confirming the USDC amount settled via x402, and a 'request' field with a UUID and status URL for tracking the request.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "model": {
   "type": "string"
  },
  "tools": {
   "type": "array",
   "items": {}
  },
  "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
   }
  },
  "max_turns": {
   "type": "number"
  },
  "max_tokens": {
   "type": "number"
  },
  "temperature": {
   "type": "number"
  },
  "max_tool_calls": {
   "type": "number"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "data": {},
  "payment": {
   "scheme": "exact",
   "settledUsdc": "0.001000",
   "authorizedMaxUsdc": "0.001000"
  },
  "request": {
   "id": "00000000-0000-4000-8000-000000000000",
   "statusUrl": "/requests/00000000-0000-4000-8000-000000000000"
  },
  "success": true
 }
}
```

## More

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