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

# xAI

> Observe the power of Grok and Grok Vision with AgentOps

[xAI](https://x.ai) develops the Grok and Grok Vision models. Explore their developer docs [here](https://docs.x.ai/docs).

**1. Install the AgentOps SDK**

```bash pip  theme={null}
pip install agentops
```

```bash poetry theme={null}
poetry add agentops
```

**2. Install XAI libraries**

> [!NOTE]
>
> xAI models can be accessed via OpenAI or Anthropic clients.

To install the OpenAI client, run:

```bash pip theme={null}
pip install openai
```

```bash poetry theme={null}
poetry add openai
```

To install the Anthropic client, run:

```bash pip theme={null}
pip install anthropic
```

```bash poetry theme={null}
poetry add anthropic
```

**3. Add AgentOps to your code**

> [!NOTE]
>
> Make sure to call `agentops.init` before calling any `openai`, `cohere`, `crew`, etc models.

```python python theme={null}
import agentops

agentops.init(<INSERT YOUR API KEY HERE>)

# Your code here...

agentops.end_session("Success")
```

> [!TIP]
>
> Set your API key as an `.env` variable for easy access.

```python .env theme={null}
AGENTOPS_API_KEY=<YOUR API KEY>
```

Read more about environment variables in [Advanced Configuration](https://docs.agentops.ai/v1/usage/advanced-configuration.md)

**4. Run your Analysis**

Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your XAI analysis! 🔍

> [!TIP]
>
> AgentOps automatically tracks your XAI metrics and visualizations in the Dashboard

## Full Examples

```python openai theme={null}
from openai import OpenAI

XAI_API_KEY = "you xai api key"
client = OpenAI(
    api_key=XAI_API_KEY,
    base_url="https://api.x.ai/v1",
)

completion = client.chat.completions.create(
    model="grok-beta",
    messages=[
        {"role": "system", "content": "You are Grok, a chatbot inspired by the Hitchhikers Guide to the Galaxy."},
        {"role": "user", "content": "What is the meaning of life, the universe, and everything?"},
    ],
)

print(completion.choices[0].message)
```

```python anthropic theme={null}
from anthropic import Anthropic

XAI_API_KEY = "you xai api key"
client = Anthropic(
    api_key=XAI_API_KEY,
    base_url="https://api.x.ai",
)
message = client.messages.create(
    model="grok-beta",
    max_tokens=128,
    system="You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy.",
    messages=[
        {
            "role": "user",
            "content": "What is the meaning of life, the universe, and everything?",
        },
    ],
)
print(message.content)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.