Integration and examples

Grok API through CLODEx

Grok is xAI’s model family. Text-model access is not access to the X feed or real-time search. This guide connects an ordinary text request and makes that boundary explicit.

What the request needs

Select an available Grok model from /v1/models using your CLODEx key. Do not pass a GPT or Claude ID and expect the gateway to choose Grok. If the model is absent, resolve access and group constraints first.

Set CLODEX_API_KEY and CLODEX_MODEL on your server. The OpenAI-compatible base URL is https://clodex.xyz/v1. This is distinct from the direct xAI API, with separate credentials and billing.

Check a key

One text request

The example enables neither search, tools nor automatic retries. Its timeout is 60 seconds. It checks the text contract, not image support or function execution.

import json
import os
from urllib.request import Request, urlopen

payload = {
    "model": os.environ["CLODEX_MODEL"],
    "messages": [{"role": "user", "content": "Reply with one word: ready"}],
    "stream": False,
}
request = Request(
    "https://clodex.xyz/v1/chat/completions",
    data=json.dumps(payload).encode("utf-8"),
    headers={
        "Authorization": "Bearer " + os.environ["CLODEX_API_KEY"],
        "Content-Type": "application/json",
    },
    method="POST",
)
with urlopen(request, timeout=60) as response:
    result = json.load(response)
choices = result.get("choices", [])
if not choices or choices[0].get("finish_reason") != "stop":
    raise RuntimeError("Incomplete text response")
text = choices[0].get("message", {}).get("content")
if not isinstance(text, str) or not text.strip():
    raise RuntimeError("Missing text")
print(text)

A model is not a search service

An answer about a current event may come from model knowledge rather than a fresh source. Verification requires a retrieved document, its date and a citation. A confident tone or mention of X does not prove that a search ran.

If your product needs search, use an explicitly supported tool and supply retrieved excerpts to the model. Match citations to actual retrieved results rather than accepting a plausible-looking URL.

Example: answer from supplied evidence only

Supply two excerpts: [A] “Version 2.0 shipped on October 10 and adds CSV export”; [B] “SSO is in development.” Ask which feature shipped and which has not. The expected distinction is released CSV export versus no evidence of an SSO release.

The data is synthetic. The check needs no network access and does not benchmark Grok. It tests whether the answer separates a stated event from an assumption.

Errors and retries

A 401 needs a credential check, not repeated requests. For 429, inspect the limit and honor Retry-After when supplied. A client timeout does not prove the server never started processing; inspect request state and usage before retrying.

Record any fallback explicitly. Models can differ in format handling, tool fields and output limits. Do not present a fallback response as the Grok model the user selected.

Documentation · Rates

Documentation and example scope

Connection settings follow CLODEx documentation. Examples target the stated protocol; they are not recorded inference results and do not promise identical features across models. A successful generation request can incur a charge.

Client configuration · API protocols

Frequently asked questions

Does the example access X?

No. It sends text only and configures no search tool.

Why is there no fixed model ID?

Availability depends on the key’s catalog. A hard-coded unavailable ID would make the example unusable.

Can every failed request be retried?

No. Retrying does not fix authorization or schema errors. After a timeout, first check whether the request was accepted.

Connect CLODEX API to your application

One key-management layer, compatible endpoints and several LLM families for apps, agents and developer tools.