# @standardagents/xai

xAI provider package for Standard Agents using the official @ai-sdk/xai package

> **Info:**
>
> For direct access, set `XAI_API_KEY` in your environment. Standard Agents Builder can use hosted routing through `STANDARD_AGENTS_API_KEY` when the provider key is absent. Hosted access depends on platform configuration.

## Overview

The `@standardagents/xai` package provides a Standard Agents provider for Grok chat and image models. It uses the official `@ai-sdk/xai` package, supports Grok streaming responses, and routes `grok-imagine-image*` models through xAI's image generation/edit APIs.

- Key Features

  - Official `@ai-sdk/xai` integration
  - Grok chat model streaming, reasoning, and tool calls
  - xAI provider-executed tools such as `web_search`, `x_search`, and `code_execution`
  - xAI image generation and image editing support
  - Built-in pricing for documented Grok text models
  - Request inspection support in the admin UI

## Installation

```bash pnpm
pnpm add @standardagents/xai
```

## Quick Start

```typescript
import { defineModel } from '@standardagents/spec';
import { xai } from '@standardagents/xai';

export default defineModel({
  name: 'grok-default',
  provider: xai,
  model: 'grok-4-0709',
  providerOptions: {
    reasoningEffort: 'high',
  },
});
```

## Common Models

- `grok-4-0709`
- `grok-4-fast-reasoning`
- `grok-4-1-fast-reasoning`
- `grok-code-fast-1`
- `grok-3`
- `grok-imagine-image`
- `grok-imagine-image-pro`

## Provider Options

Chat options include `reasoningEffort`, `logprobs`, `topLogprobs`, `store`, and `previousResponseId`.

Image options include `aspect_ratio`, `output_format`, `resolution`, `quality`, and `numberOfImages`.

## Provider Tools

xAI built-in tools are provider-executed. Enable provider-defined names on the
model and select them from prompts:

```typescript
export default defineModel({
  name: 'grok-research',
  provider: xai,
  model: 'grok-4-0709',
  providerTools: ['x_search', 'web_search', 'code_execution'],
});
```

Image and video understanding helpers are modeled as provider tool names in
Standard Agents Builder and translated by `@standardagents/xai` into the corresponding xAI
search-tool options. Completed xAI tool calls are reported through the generic
Standard Agents provider-tool log path, not the local function executor.

## Environment Setup

```bash .dev.vars
XAI_API_KEY=...
```
