{"uid":"cap_j3J1I6ZUYHXHIJOt0-Zc-","slug":"x402engine-grok-code-llm-api-9427ec7e","name":"x402engine Grok Code LLM API","description":"x402engine — xAI's build-focused model — code generation, analysis, and agentic implementation work","url":"https://x402engine.app/api/llm/grok-code?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","bodyType","body","method"],"properties":{"body":{"type":"object","required":["messages"],"properties":{"seed":{"type":"integer","description":"Model-supported seed; see /docs/llm-capabilities.md."},"tools":{"type":"array","items":{"type":"object","required":["function"],"properties":{"type":{"enum":["function"],"type":"string"},"function":{"type":"object","properties":{"name":{"type":"string"},"strict":{"type":"boolean"},"parameters":{"type":"object"},"description":{"type":"string"}}}}},"description":"Client-executed function definitions; return results using role=tool and tool_call_id."},"top_p":{"type":"number","description":"Model-supported top_p; see /docs/llm-capabilities.md."},"stream":{"type":"boolean","description":"Return live OpenAI-compatible SSE after payment settlement."},"plugins":{"type":"array","items":{"type":"object","required":["pdf"],"properties":{"id":{"enum":["file-parser"],"type":"string"},"pdf":{"type":"object","properties":{"engine":{"enum":["native"],"type":"string"}}}}},"description":"Optional native PDF parser only; automatically enabled for file inputs."},"logprobs":{"type":"boolean","description":"Model-supported logprobs; see /docs/llm-capabilities.md."},"messages":{"type":"array","items":{"type":"object","anyOf":[{"required":["content"]},{"required":["tool_calls"]}],"required":["role"],"properties":{"name":{"type":"string"},"role":{"enum":["system","developer","user","assistant","tool"],"type":"string"},"content":{"oneOf":[{"type":"string"},{"type":"null"},{"type":"array","items":{"type":"object","required":["type"],"properties":{"type":{"enum":["text","image_url","file"],"type":"string"}},"additionalProperties":true},"maxItems":100,"minItems":1}]},"refusal":{"type":["string","null"]},"reasoning":{"type":"string"},"tool_calls":{"type":"array","items":{"type":"object"}},"annotations":{"type":"array","items":{"type":"object"}},"tool_call_id":{"type":"string"},"cache_control":{"type":"object"},"reasoning_details":{"type":"array","items":{"type":"object"}}},"additionalProperties":false},"maxItems":100,"minItems":1,"description":"Text or model-supported multimodal messages; assistant tool calls may have null content"},"reasoning":{"type":"object","description":"Model-supported reasoning; see /docs/llm-capabilities.md."},"max_tokens":{"type":"integer","example":1024,"description":"Total output budget, including reasoning. Use this or max_completion_tokens."},"temperature":{"type":"number","description":"Model-supported temperature; see /docs/llm-capabilities.md."},"tool_choice":{"oneOf":[{"enum":["auto","none","required"],"type":"string"},{"type":"object"}],"description":"Model-supported tool_choice; see /docs/llm-capabilities.md."},"top_logprobs":{"type":"integer","description":"Model-supported top_logprobs; see /docs/llm-capabilities.md."},"stream_options":{"type":"object","description":"Optional include_usage boolean; usage is always requested upstream."},"response_format":{"type":"object","description":"Model-supported response_format; see /docs/llm-capabilities.md."},"include_reasoning":{"type":"boolean","description":"Model-supported include_reasoning; see /docs/llm-capabilities.md."},"max_completion_tokens":{"type":"integer","description":"Alias for total output budget; bounded by model maxOutputTokens."}},"additionalProperties":false},"type":{"type":"string","const":"http"},"method":{"enum":["POST"],"type":"string"},"bodyType":{"enum":["json","form-data","text"],"type":"string"}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","required":["choices","content"],"properties":{"model":{"type":"string"},"usage":{"type":"object","description":"Provider token and usage accounting, when returned."},"choices":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer"},"message":{"type":"object","properties":{"role":{"type":"string"},"content":{"type":["string","null"]},"tool_calls":{"type":"array","items":{"type":"object"}}}},"finish_reason":{"type":["string","null"]}}}},"content":{"type":"string","description":"Convenience copy of the first assistant message's text."}}}}}}},"responseSchema":{"type":"json","example":{"model":"x-ai/grok-build-0.1","choices":[{"index":0,"message":{"role":"assistant","content":"Hello!"},"finish_reason":"stop"}],"content":"Hello!"}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.015149","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.015149/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.015149","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.015149","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_mfqhqQms6a3du6NmvCtPz","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.015149","costPer":"request","priority":0,"asset":null,"unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Send chat messages to xAI's Grok code-focused model via HTTP 402 micropayment, returning an OpenAI-compatible response","exampleAgentPrompt":"Use the Grok code model to write a Python function that parses a CSV file, groups rows by a date column, and returns the sum of a numeric column per group — include type hints and a docstring.","exampleUseCases":[{"title":"Automated code review assistant","prompt":"Use Grok's coding model to review this Python function and suggest improvements for readability, performance, and edge case handling: def calc(a, b): return a/b"},{"title":"Code generation for data pipeline","prompt":"Have the Grok code model write a Node.js script that reads from a PostgreSQL database, transforms the results into JSON, and posts them to a REST API endpoint — include error handling."},{"title":"Function-calling agent for debugging","prompt":"Send this conversation to the Grok code model with my debugger tool definition so it can call it to identify why this TypeScript code throws a 'cannot read property of undefined' error at runtime."}],"resultDescription":"An OpenAI-compatible JSON response containing the model name ('x-ai/grok-build-0.1'), an array of choices each with an index, finish_reason, and message object (role + content), plus a top-level content field with the assistant's reply text. When streaming is enabled, returns SSE chunks in OpenAI format after payment settles.","failureModes":["Payment not settled — 402 response if USDC/USDm payment fails or is insufficient","Missing required 'messages' field — validation error","Model context length exceeded if conversation history is too long","Tool call loop if function results are not returned correctly via role=tool","Streaming timeout if SSE connection drops mid-response","Unsupported parameter (e.g. seed or logprobs) if model capability not listed in /docs/llm-capabilities.md"],"whenToPreferThis":"Choose this endpoint when you need a coding-specialized LLM (xAI Grok code variant) without a subscription, paying only $0.015 per call via USDC micropayment. Ideal for agents that need on-demand code generation, debugging, or code review without managing API keys or rate limits. Prefer over generic chat models when the task is code-centric and you want Grok's code-tuned reasoning.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-29T07:21:08.678Z","isFirstParty":false,"canonicalSlug":"x402engine-grok-code-llm-api-9427ec7e"}