> ## Documentation Index
> Fetch the complete documentation index at: https://magicads.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# xAI (Grok) Setup

> Connect xAI (Grok) to MagicAds — a Copy Studio provider that drives AI ad-copy generation with the Grok model. It does not power image or video.

## Introduction

xAI is a **Copy Studio** provider — it drives AI ad-copy generation with the Grok model. It does **not** power image or video generation; for those you'll use other providers (e.g. Gemini or OpenAI for images; Gemini/Veo, Runway, or fal.ai for video).

This guide walks you through getting an xAI key, adding it in MagicAds, and the model it unlocks.

## How keys are stored

All AI provider keys live in the **AI Settings** screen and are stored **encrypted** in the database. There are no `.env` edits — keys are injected into the drivers at runtime. Users never supply their own key; every generation runs on the admin's key.

<Note>
  A model only becomes available to users when **both** are true: the xAI API key is saved **and** the Grok model is **enabled** in the vendor modal.
</Note>

## Before you start

* Admin access to your MagicAds platform.
* An xAI account with billing/credits set up.

## Part 1 — Get your xAI API key

<Steps>
  <Step title="Sign in to the xAI Console">
    Go to the [xAI Console](https://console.x.ai/) and sign in or create an account. On first sign-in you may be asked to create a **team**.
  </Step>

  <Step title="Add billing / credits">
    Open the **Billing** section and add a payment method or purchase credits. xAI charges you directly for usage — separate from your MagicAds platform credits.

    <Tip>
      If you also buy X API credits, xAI offers bonus API credits — check the current promotion on the console's billing page.
    </Tip>
  </Step>

  <Step title="Create an API key">
    Open the **API Keys** section and click **Create API key**. Give it a name (e.g. "MagicAds") and create it.

    <Warning>
      The key is shown **only once**. Copy it immediately and store it somewhere safe.
    </Warning>
  </Step>

  <Step title="Confirm model access">
    Make sure your account has credits and access to the `grok-4.3` model.
  </Step>
</Steps>

## Part 2 — Add the key in MagicAds

<Steps>
  <Step title="Open AI Settings">
    In your platform, go to **Admin → AI Settings**.
  </Step>

  <Step title="Open the xAI vendor">
    Click the **xAI** vendor card to open its configuration modal.
  </Step>

  <Step title="Paste the key">
    Paste your API key into the **API key** field. Leaving it blank keeps the existing key unchanged. If a **Base URL** is shown, you can leave it at its default.
  </Step>

  <Step title="Enable the model">
    Toggle on the **Grok 4.3** copy model and set its **credit cost** (what a user is charged per generation).
  </Step>

  <Step title="Save">
    Click **Save**. The xAI card shows as connected and Grok appears in the Copy Studio.
  </Step>
</Steps>

<Note>
  There is no "test connection" button. To verify, enable the model and run a quick generation in the Copy Studio.
</Note>

## Part 3 — Supported xAI models

### Copy Studio

| Model    | Model ID   | Tier    | Default credits | Best for                                                                                                            |
| -------- | ---------- | ------- | --------------- | ------------------------------------------------------------------------------------------------------------------- |
| Grok 4.3 | `grok-4.3` | Premium | 2               | xAI's flagship — its most intelligent and fastest Grok, with a 1M-token context. Strong for long or complex briefs. |

That's the only model xAI provides here. There are **no xAI image or video models**.

<Note>
  The credit cost shown is the seeded default. You can change it in the vendor modal. It's what your platform charges users in credits — not xAI's price.
</Note>

## Part 4 — Make xAI the default copy engine (optional)

In the global section of **AI Settings** you can set the **default copy engine** to xAI so Grok is pre-selected for users. You can also toggle the Copy Studio on/off and control free-tier access there.

## Troubleshooting

| Symptom                               | Likely cause                                                    | Fix                                                                  |
| ------------------------------------- | --------------------------------------------------------------- | -------------------------------------------------------------------- |
| Grok doesn't appear in Copy Studio    | Key missing or model disabled                                   | Add the key in the xAI vendor modal and enable Grok 4.3, then Save.  |
| "The payload is invalid." on generate | Saved key can't be decrypted (e.g. after an environment change) | Re-enter the xAI key in AI Settings and Save to refresh it.          |
| xAI API errors / 401                  | Invalid key or no billing/model access                          | Re-check the key, billing, and `grok-4.3` access in the xAI Console. |
| Looking for xAI image/video           | Not supported                                                   | xAI is copy-only here; use an image/video provider instead.          |

<Note>
  Keys are stored encrypted and applied at runtime. No `.env` changes or commands are needed after saving.
</Note>
