{"uid":"cap_vnOu6-7BwCNebywAFkkGJ","slug":"grok-code-execution-via-locus-x402-83eb43d3","name":"Grok Code Execution via Locus x402","description":"xAI models — chat, web/X search, code execution, image generation/editing, and text-to-speech.","url":"https://grok.x402.paywithlocus.com/grok/code-execution","method":"POST","headers":{},"bodySchema":{"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"}}},"responseSchema":{"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}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.001","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_KpqiNDAuegwvjfKw2W5gK","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.001","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Run code via xAI Grok models with sandboxed code execution enabled, billed per call over the x402 micropayment protocol.","exampleAgentPrompt":"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.","exampleUseCases":[{"title":"AI-assisted data analysis script","prompt":"Use Grok grok-4.5 with code execution to load this CSV data I'm pasting, compute the mean and standard deviation for each numeric column, and show me the results — limit it to 1024 tokens and up to 5 tool calls."},{"title":"Math problem solved by running code","prompt":"Ask Grok grok-4.3 to solve this integral numerically using code execution: integrate sin(x)*e^(-x) from 0 to infinity. Give it up to 512 tokens and 3 tool calls."},{"title":"Code debugging with execution feedback","prompt":"I have a buggy Python function that's supposed to sort a list of dicts by a nested key — can you have Grok grok-4.5 run the code, identify the bug, fix it, and verify the fix executes correctly? Use up to 2048 output tokens and allow up to 5 tool calls."}],"resultDescription":"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.","failureModes":["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"],"whenToPreferThis":"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.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-15T12:41:33.333Z","isFirstParty":false}