# Connect to xAI / Grok

Connect your xAI team to Finora to track Grok API spend automatically — including cost per model and per hour, grounded in xAI's actual billed numbers.

> **Before you start**
>
> * You need to be a **team admin** on xAI. Only admins can create Management Keys and view team billing.
> * The **Management Key** is different from the API key you use to call Grok models. You'll need to create a separate one specifically for billing access.

## Overview

You'll create an xAI **Management Key** in the xAI Console, copy your **Team ID**, and paste both into Finora. Together they let Finora read your team's billing analytics — and nothing else. The Management Key can't be used to call Grok or change your team's settings.

## Step 1: Create an xAI Management Key

1. Sign in to the [**xAI Console**](https://console.x.ai) as a team admin.
2. Open **Settings → Management Keys**.
3. Click **+ Create Key** (or the equivalent button if the wording has changed).
4. Give it a clear name like `Finora Integration` and create it.
5. **Copy the key immediately** — xAI only shows it once.

> If you don't see **Management Keys** in Settings, you're either not a team admin or you're looking at the regular API key page. Management Keys live in their own settings section.

## Step 2: Find your Team ID

1. In the xAI Console, your team is the billing/usage scope shown in the header or under your account menu.
2. Open any page that shows the team URL or copy the **Team ID** from **Settings → Team**.
3. The Team ID looks like `team_xxxxxxxx`.

> If you manage multiple teams, make sure you grab the Team ID for the team whose spend you want to track. Finora connects one team per credential.

## Step 3: Connect xAI to Finora

1. In Finora, click **Settings** in the sidebar, then open the **API Keys** tab.
2. From the **Provider** dropdown, choose **xAI**.
3. Fill in:
   * **xAI Management Key** — the value you copied in Step 1
   * **xAI Team ID** — the value you copied in Step 2
4. Click **Save**.

Finora confirms the credentials work. On success, xAI appears in your connected providers list, and Grok spend flows in at the next refresh.

## What Finora tracks for xAI

* Cost per model per hour, in USD
* Which Grok model was used (e.g. `grok-4`, `grok-3`)
* The team the spend belongs to

The numbers are taken straight from xAI's billing analytics, so they match the totals you see in the xAI Console.

> **A note on token counts** xAI's billing analytics expose authoritative cost figures, but per-event token counts aren't currently available through the same endpoint. Cost numbers, model breakdowns, and time-series totals are exact; per-event input/output token columns will read as zero until xAI exposes those fields. We'll backfill token counts as soon as the upstream API supports it.

## FAQs

**Why do I need a Management Key separate from my regular API key?** xAI splits credentials by purpose. Regular API keys can call Grok but can't read team billing. Management Keys can read billing but can't call models. Finora needs the second kind.

**Can a non-admin team member create the Management Key?** No. Only xAI team admins can issue Management Keys. If you don't have admin rights, ask your team owner to generate it for you.

**My team uses prepaid credits — does the integration still work?** Yes. xAI's billing analytics report consumption regardless of whether you're on prepaid credits or postpaid invoiced billing. Finora reflects whatever xAI reports as billed `usd`.

**Saving failed with `401 Unauthorized`. What's wrong?** Common reasons:

* The Management Key was revoked in xAI.
* The user who created the key lost team admin rights.
* The key was copied with extra whitespace.
* You pasted a regular API key instead of a Management Key by mistake.

Create a fresh Management Key in **Settings → Management Keys** and try again.

**How do I rotate the Management Key?** Create a new Management Key in the xAI Console, paste it into Finora **Settings → API Keys → Update**, save, and then revoke the old key in xAI.

**Will Finora track my xAI prepaid top-ups or invoices?** Finora tracks the spend side — what you've used. The top-up and invoice ledger lives in the xAI Console.

## Removing the integration

Open **Settings → API Keys**, find the xAI row, click the trash icon, and confirm. Your stored credentials are deleted. We recommend you also revoke the Management Key in xAI afterwards.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.finora.services/billing-integrations/ai-providers/connect-to-xai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
