🎬 MEDIA PLACEHOLDER · MX-MEDIA-4090 · [SCREENSHOT]
[SCREENSHOT_DESCRIPTION]: The xAI connection card in the ModuleX integrations/credentials UI.
[SCREENSHOT_DETAILS]: Capture the API Key Authentication form for xAI in the credential-management UI: the
API Key field (masked, sample xai-…), the optional Base URL field defaulted to https://api.x.ai/v1, and the “Test connection” / “Save” controls. Light theme, 16:9, crop to the card.What you need
An xAI API key
Create a key in the xAI Console under API Keys → Create new API key. xAI keys start with
xai- (for example xai-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx). ModuleX validates the key against the pattern ^xai-[a-zA-Z0-9\-_]{20,}$ before saving it.A ModuleX organization and an owner/admin role
Credentials are scoped to an organization. Connecting and managing integrations requires the owner or admin role — the
member role is retired. See roles & permissions.A ModuleX API key (for programmatic setup)
To connect xAI over the API or an SDK, you need a ModuleX API key (
mx_live_…) and your organization id. See authentication.Connect xAI
You connect xAI by storing your xAI API key as a credential for thexai integration. You can do this in the app or programmatically.
In the app
- Open the integrations catalog and select xAI, or open Settings → Credentials.
- Choose API Key Authentication and paste your xAI key.
- Optionally set a custom Base URL (defaults to
https://api.x.ai/v1) — only needed for xAI-compatible gateways. - Save. ModuleX validates the key with a minimal request before storing it (see Test a key before saving).
api_key. Its fields are:
Your xAI API key. Stored encrypted and never returned in plaintext. Pattern
^xai-[a-zA-Z0-9\-_]{20,}$; sample format xai-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.Optional custom API base URL, only needed when pointing at an xAI-compatible API. Must match
^https?://.*.Over the API or an SDK
Create the credential withPOST /credentials. ModuleX detects the credential type from the body: an auth_data.api_key value is stored as an api_key credential. Set make_default: true to make this the default xAI credential for the organization.
Every request authenticates with Authorization: Bearer mx_live_… plus the X-Organization-ID header (see authentication).
The new credential’s identifier. A
201 response returns the credential metadata; the secret is never echoed back.Creating, listing, and managing credentials and the integration catalog requires the owner or admin role in the organization. A caller without that role receives a
403. The integration-catalog read routes (for example GET /integrations/llm-providers/xai) are also owner/admin-gated.Test a key before saving
UsePOST /credentials/test-temporary to validate an xAI key without storing it. ModuleX runs the provider’s test call — a 10-token POST to https://api.x.ai/v1/chat/completions against grok-4-fast — and reports success when the response status is 200 and includes the fields id, choices, and model.
true when the test call succeeds.The HTTP status returned by xAI’s test endpoint (
200 on success).How the credential was validated. For xAI this is
api_call.The cost class of the test call. For xAI this is
minimal (a 10-token request).Available models
ModuleX serves Grok models from the catalog atGET /integrations/llm-providers/xai. The catalog is read-only metadata used by the credential UI and the builder — it is not the execution path. The models below are the ones ModuleX currently advertises for xAI.
| Model id | Display name | Max input tokens | Max output tokens | Vision | Input $/1M | Output $/1M |
|---|---|---|---|---|---|---|
grok-4-0709 | Grok 4 | 256,000 | 256,000 | Yes | $3.00 | $15.00 |
grok-code-fast-1 | Grok Code Fast | 256,000 | 10,000 | No | $0.20 | $1.50 |
grok-4-fast | Grok 4 Fast | 2,000,000 | 30,000 | Yes | $0.20 | $0.50 |
Prices in the table are xAI’s per-token rates as recorded in the ModuleX catalog, in USD per 1,000,000 tokens. Because xAI is BYOK, these are the rates xAI charges you directly — they are not ModuleX credits. See BYOK billing.
The model list is served from the ModuleX catalog and may change as xAI releases or deprecates models. Always read
GET /integrations/llm-providers/xai for the current set rather than hard-coding ids. Catalog reads are cached for up to 10 minutes.Read the model catalog
models array contains the entries shown above, plus an auth_schemas array describing the api_key scheme. A truncated example:
Catalog detail (truncated)
Use Grok in ModuleX
Once xAI is connected, select a Grok model id wherever a model can be chosen:LLM node
Call Grok with prompts, variables, and structured output inside a workflow.
Agent node
Run an autonomous step where Grok can call tools and loop.
Chat
Pick Grok as the model for a chat conversation.
Assistant
Configure the Assistant to reason and act with a Grok model.
xai integration. Set a different default with POST /credentials/{credential_id}/set-default. See managing credentials.
BYOK billing
xAI is bring-your-own-key, which changes how usage is billed compared with ModuleX-managed models.BYOK (xAI)
Token usage is billed by xAI against your own API key. ModuleX adds no credit charge and no markup for the model call itself. BYOK usage is recorded for analytics only — it does not consume ModuleX credits.
Managed (modulexai)
ModuleX provisions the model and bills it in credits through the usage gate, applying a system margin. Use this when you do not want to manage a provider account.
- No ModuleX credit cost for tokens. A Grok call made with your xAI key is not metered in credits. xAI invoices you directly at its own rates (the per-million-token prices in the model table).
- Other ModuleX usage still applies. Running a workflow or a turn through the Assistant can still consume the flat per-run credit and may pass through the billing gate even when the model itself is BYOK. See credits & metering and usage gating & limits.
- Rate limits and quotas are xAI’s. Token-rate limits, monthly spend caps, and model availability for a BYOK key are governed by your xAI account, not by ModuleX.
BYOK is available on all plans — there is no separate ModuleX entitlement that gates connecting your own xAI key. The pricing matrix on the marketing site lists BYOK for every tier; the only ModuleX-side billing that applies to a BYOK call is the non-model usage described above. TBD: confirm with the billing owner that no per-call ModuleX surcharge applies to BYOK model calls before treating “no markup” as a guarantee.
Errors
Catalog and credential operations return ModuleX’s standard error shapes. See errors & status codes for the full taxonomy.| Status | When it happens | Shape |
|---|---|---|
400 | Invalid auth_data/auth_type on credential create, or asking a typed endpoint for the wrong integration type (for example xai is not a tool). | {detail: string} |
401 | Missing or invalid Authorization / missing X-Organization-ID. | {detail: string} |
403 | Caller is not an owner/admin in the organization. | {detail: string} |
404 | Unknown provider, for example GET /integrations/llm-providers/<unknown> returns LLM provider not found. | {detail: string} |
422 | Query/parameter validation error. | {detail: [ ... ]} |
500 | Unhandled server error. | {detail: string} |
Related
LLM providers
All providers, and how managed vs BYOK selection works.
ModuleX-managed models
The credit-billed managed alternative to BYOK.
Authentication & credentials
How integrations authenticate and the auth schema variants.
Managing credentials
Create, default, rotate, and scope credentials.