SpyBara
Go Premium

Documentation 2026-11-03 23:00 UTC to 2026-11-04 23:01 UTC

5 files changed +76 −12. View all changes and history on the product overview
2026
Tue 10 15:57 Mon 9 23:00 Sun 8 23:57 Sat 7 22:59 Fri 6 23:59 Thu 5 23:58 Wed 4 23:01 Tue 3 23:00 Mon 2 23:57 Sun 1 23:02
Details

157 -H "Authorization: Bearer <Your Management API Key>"157 -H "Authorization: Bearer <Your Management API Key>"

158```158```

159 159 

160## Usage reporting

161 

162To pull your team's cost or token usage programmatically, such as daily token counts per model, call `POST /v1/billing/teams/{team_id}/usage` with your management key. Measure tokens with the value `units`, and group by `unit_type` and `description` to split the counts by token type and model. [Daily token usage](/developers/rest-api-reference/management/billing#daily-token-usage) lists the accepted values and fields, with an example request.

163 

160## Audit Logs164## Audit Logs

161 165 

162You can retrieve audit logs for your team. Audit events track changes to team settings, API keys, team membership, and other administrative actions.166You can retrieve audit logs for your team. Audit events track changes to team settings, API keys, team membership, and other administrative actions.

Details

16 16 

17* Requests to `grok-imagine-image-quality` on `/v1/images/generations` and `/v1/images/edits` are served by **`grok-imagine-image-2.0` with `quality: "low"`**.17* Requests to `grok-imagine-image-quality` on `/v1/images/generations` and `/v1/images/edits` are served by **`grok-imagine-image-2.0` with `quality: "low"`**.

18* The request and response shapes are unchanged. Every parameter accepted today is accepted after the switch, and `grok-imagine-image-2.0` additionally accepts `quality`, up to five source images for editing, and the `21:9` and `5:2` aspect ratios.18* The request and response shapes are unchanged. Every parameter accepted today is accepted after the switch, and `grok-imagine-image-2.0` additionally accepts `quality`, up to five source images for editing, and the `21:9` and `5:2` aspect ratios.

19* The `model` field on responses reports the model that served the request, so you can confirm the switch from your logs.19* To confirm the switch, check [`usage.cost_in_usd_ticks`](/developers/cost-tracking) on responses. It reflects the `grok-imagine-image-2.0` low price: $0.04 per 1K image and $0.06 per 2K image, plus $0.01 per input image on edits. gRPC responses (xAI SDK) also report `model` as `grok-imagine-image-2.0-low`.

20* Requests to `grok-imagine-image-pro`, which [already redirect](/developers/migration/may-15-retirement) to `grok-imagine-image-quality`, follow it to `grok-imagine-image-2.0` at `low`.20* Requests to `grok-imagine-image-pro`, which [already redirect](/developers/migration/may-15-retirement) to `grok-imagine-image-quality`, follow it to `grok-imagine-image-2.0` at `low`.

21 21 

22## Pricing impact22## Pricing impact

Details

17 -H "Authorization: Bearer $XAI_API_KEY" \17 -H "Authorization: Bearer $XAI_API_KEY" \

18 -H "Content-Type: application/json" \18 -H "Content-Type: application/json" \

19 -d '{19 -d '{

20 "model": "grok-imagine-image-quality",20 "model": "grok-imagine-image-2.0",

21 "prompt": "Add a party hat to the dog",21 "prompt": "Add a party hat to the dog",

22 "image": { "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" },22 "image": { "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" },

23 "response_format": "url"23 "response_format": "url"


32 32 

33response = client.image.sample(33response = client.image.sample(

34 prompt="Add a party hat to the dog",34 prompt="Add a party hat to the dog",

35 model="grok-imagine-image-quality",35 model="grok-imagine-image-2.0",

36 image_file_id="file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a", # instead of image_url36 image_file_id="file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a", # instead of image_url

37)37)

38 38 


47 -H "Authorization: Bearer $XAI_API_KEY" \47 -H "Authorization: Bearer $XAI_API_KEY" \

48 -H "Content-Type: application/json" \48 -H "Content-Type: application/json" \

49 -d '{49 -d '{

50 "model": "grok-imagine-image-quality",50 "model": "grok-imagine-image-2.0",

51 "prompt": "Blend these two scenes into one cohesive composition",51 "prompt": "Blend these two scenes into one cohesive composition",

52 "images": [52 "images": [

53 { "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" },53 { "file_id": "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a" },


60```python customLanguage="pythonXAI"60```python customLanguage="pythonXAI"

61response = client.image.sample(61response = client.image.sample(

62 prompt="Blend these two scenes into one cohesive composition",62 prompt="Blend these two scenes into one cohesive composition",

63 model="grok-imagine-image-quality",63 model="grok-imagine-image-2.0",

64 image_file_ids=[64 image_file_ids=[

65 "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a",65 "file_7de029f4-eb66-42ee-87f8-b2a9d9e7466a",

66 "file_2cd998e7-bf12-44aa-92c8-e3d1f1c1234f",66 "file_2cd998e7-bf12-44aa-92c8-e3d1f1c1234f",

rate-limits.md +1 −1

Details

41| grok-4.20-0309-non-reasoning | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |41| grok-4.20-0309-non-reasoning | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |

42| grok-build-0.1 | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |42| grok-build-0.1 | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |

43| grok-4.20-multi-agent-0309 | T0: 9, T1: 12, T2: 18, T3: 31, T4: 56 | T0: 2.5M, T1: 3.7M, T2: 6.2M, T3: 11M, T4: 21M |43| grok-4.20-multi-agent-0309 | T0: 9, T1: 12, T2: 18, T3: 31, T4: 56 | T0: 2.5M, T1: 3.7M, T2: 6.2M, T3: 11M, T4: 21M |

44| grok-imagine-image-2.0 | T0: 6, T1: 12, T2: 25, T3: 50, T4: 100 | — |

45| grok-imagine-image | T0: 6, T1: 12, T2: 25, T3: 50, T4: 100 | — |44| grok-imagine-image | T0: 6, T1: 12, T2: 25, T3: 50, T4: 100 | — |

45| grok-imagine-image-2.0 | T0: 6, T1: 12, T2: 25, T3: 50, T4: 100 | — |

46| grok-imagine-video | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |46| grok-imagine-video | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |

47| grok-imagine-video-1.5 | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |47| grok-imagine-video-1.5 | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |

48| grok-imagine-video-1.5-lite | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |48| grok-imagine-video-1.5-lite | T0: 10, T1: 20, T2: 39, T3: 79, T4: 158 | — |

Details

176 176 

177 * `unitType` (string) — The unit in which the price is measured.177 * `unitType` (string) — The unit in which the price is measured.

178 178 

179 * `unitPrice` (string) — The price per unit (1/1\_000\_000 USD cents).179 * `unitPrice` (string) — The price per unit in ticks of 1e-10 USD (1/100\_000\_000 USD cents).

180 180 

181 * `numUnits` (string) — The number of units.181 * `numUnits` (string) — The number of units.

182 182 


450 450 

451 * `unitType` (string) — The unit in which the price is measured.451 * `unitType` (string) — The unit in which the price is measured.

452 452 

453 * `unitPrice` (string) — The price per unit (1/1\_000\_000 USD cents).453 * `unitPrice` (string) — The price per unit in ticks of 1e-10 USD (1/100\_000\_000 USD cents).

454 454 

455 * `numUnits` (string) — The number of units.455 * `numUnits` (string) — The number of units.

456 456 


802 802 

803***803***

804 804 

805## Daily token usage

806 

807`POST /v1/billing/teams/{team_id}/usage` returns your team's usage as time series, bucketed by time and optionally grouped by fields such as token type and model. It reads the same data as [Usage Explorer](/console/usage). Authenticate with a management key.

808 

809Choose what to measure with `values[].name`. Each value supports only `AGGREGATION_SUM`.

810 

811| Value | Measures |

812| --- | --- |

813| `usd` | Cost in USD |

814| `units` | Tokens for token unit types; other units, such as images or audio seconds, for the rest |

815| `items` | Billing items; one request produces an item for each priced dimension |

816| `transactions` | Requests |

817 

818You can group and filter by `unit_type`, `description`, `api_key_id`, `product`, `request_ip`, `user_id`, and `unit_price`. `unit_type` is the token type, such as `Prompt text tokens`, `Cached prompt text tokens`, `Completion text tokens`, or `Reasoning text tokens`. `Prompt text tokens` counts only uncached input; cached input is reported as `Cached prompt text tokens`. `description` is the product name followed by the billed resource, usually the model.

819 

820The following request returns daily token counts for each token type and model:

821 

822```bash

823curl https://management-api.x.ai/v1/billing/teams/{team_id}/usage \

824 -X POST \

825 -H "Authorization: Bearer $XAI_MANAGEMENT_KEY" \

826 -H "Content-Type: application/json" \

827 -d '{

828 "analyticsRequest": {

829 "timeRange": {

830 "startTime": "2026-10-26 00:00:00",

831 "endTime": "2026-11-03 00:00:00",

832 "timezone": "Etc/GMT"

833 },

834 "timeUnit": "TIME_UNIT_DAY",

835 "values": [{ "name": "units", "aggregation": "AGGREGATION_SUM" }],

836 "groupBy": ["unit_type", "description"],

837 "filters": []

838 }

839 }'

840```

841 

842The response has one entry in `timeSeries` for each combination of group values. Its `group` array lists those values in `groupBy` order, so here the token type comes first and the description second. `dataPoints` has one entry per day in the range, and `values[0]` holds that day's token count.

843 

844* `startTime` and `endTime` use the format `YYYY-MM-DD HH:MM:SS` in the IANA time zone given by `timezone`, which also sets the day boundaries. `endTime` is exclusive.

845* Keep `unit_type` in `groupBy` when you measure `units`. Grouping by `description` alone adds every unit type for a model into one number.

846* If `limitReached` is `true`, the response hit its row limit and may be incomplete; shorten the time range or group by fewer fields.

847* An unknown value or field name returns HTTP 400.

848 

849### Split long- vs short-context tokens

850 

851Long-context requests are billed at higher rates (see [Pricing](/developers/pricing)), but their tokens are reported under the same `unit_type` and `description` as other tokens. To separate them, add `unit_price` to `groupBy` in the request above so that each price gets its own time series:

852 

853```json

854"groupBy": ["unit_type", "description", "unit_price"]

855```

856 

857`unit_price` is measured in 1e-10 USD per unit, so dividing it by 10,000 gives USD per million tokens; `"25000"` is $2.50 per million tokens. Match each series to the model's standard and long-context rates to tell them apart. A token type and model can have other series too, for example from [US regional endpoint](/developers/advanced-api-usage/regions) rates, custom pricing, or a price change during the time range. To return only some prices, filter on `unit_price`, e.g., `"filters": ["unit_price:>12500"]`.

858 

859***

860 

805## POST /v1/billing/teams/\{team\_id}/usage861## POST /v1/billing/teams/\{team\_id}/usage

806 862 

807Get historical usage of the API over a time period, aggregated by fields.863Get historical usage of the API (spend, token and other unit counts) over a time period,

864bucketed by time and grouped by fields. For daily token counts, sum \`units\` per day grouped by

865\`unit\_type\`.

808 866 

809### Path Parameters867### Path Parameters

810 868 


831 889 

832 * `values` (array\<object>) — Name of the fields to aggregate.890 * `values` (array\<object>) — Name of the fields to aggregate.

833 891 

834 * `name` (string) — Name of the field to measure.892 * `name` (string) — Name of the value to measure. Valid names, and the aggregations each one supports, depend on

893 the endpoint; see the endpoint's request description.

835 894 

836 * `aggregation` ("AGGREGATION\_NONE" | "AGGREGATION\_SUM" | "AGGREGATION\_AVG" | "AGGREGATION\_VAR" | "AGGREGATION\_STD" | "AGGREGATION\_MIN" | "AGGREGATION\_MAX" | "AGGREGATION\_P50" | "AGGREGATION\_P90" | "AGGREGATION\_P99" | "AGGREGATION\_P999" | "AGGREGATION\_COUNT" | "AGGREGATION\_COUNT\_DISTINCT") — Each value is an aggregate of the individual values in the time bucket. Note that not every field895 * `aggregation` ("AGGREGATION\_NONE" | "AGGREGATION\_SUM" | "AGGREGATION\_AVG" | "AGGREGATION\_VAR" | "AGGREGATION\_STD" | "AGGREGATION\_MIN" | "AGGREGATION\_MAX" | "AGGREGATION\_P50" | "AGGREGATION\_P90" | "AGGREGATION\_P99" | "AGGREGATION\_P999" | "AGGREGATION\_COUNT" | "AGGREGATION\_COUNT\_DISTINCT") — Each value is an aggregate of the individual values in the time bucket. Note that not every field

837 supports every aggregation method.896 supports every aggregation method.


865 "analyticsRequest": {924 "analyticsRequest": {

866 "timeRange": {925 "timeRange": {

867 "startTime": "2025-10-01 00:00:00",926 "startTime": "2025-10-01 00:00:00",

868 "endTime": "2025-10-07 23:59:59",927 "endTime": "2025-10-08 00:00:00",

869 "timezone": "Etc/GMT"928 "timezone": "Etc/GMT"

870 },929 },

871 "timeUnit": "TIME_UNIT_DAY",930 "timeUnit": "TIME_UNIT_DAY",

872 "values": [931 "values": [

873 {932 {

874 "name": "usd",933 "name": "units",

875 "aggregation": "AGGREGATION_SUM"934 "aggregation": "AGGREGATION_SUM"

876 }935 }

877 ],936 ],

878 "groupBy": [937 "groupBy": [

938 "unit_type",

879 "description"939 "description"

880 ],940 ],

881 "filters": []941 "filters": []