# Configure LiteLLM for Opik
from litellm.integrations.opik.opik import OpikLogger
import litellm

litellm.callbacks = ["opik"]

os.environ["XAI_API_KEY"] = "your-xai-api-key"

response = completion(
    model="xai/grok-beta",
    messages=[
        {"role": "user", "content": "What is the current state of renewable energy adoption worldwide?"}
    ]
)

print(response.choices[0].message.content)
```

## Supported Models

xAI provides access to several Grok model variants:

* **Grok Beta**: `grok-beta` - The main conversational AI model with real-time information access
* **Grok Vision Beta**: `grok-vision-beta` - Multimodal model capable of processing text and images
* **Grok Mini**: `grok-mini` - A smaller, faster variant optimized for simpler tasks

For the most up-to-date list of available models, visit the [xAI API documentation](https://docs.x.ai/).

## Real-time Information Access

One of Grok's key features is its ability to access real-time information. This makes it particularly useful for questions about current events:

```python
response = completion(
    model="xai/grok-beta",
    messages=[
        {"role": "user", "content": "What are the latest news headlines today?"}
    ]
)

print(response.choices[0].message.content)
```

## Vision Capabilities

Grok Vision Beta can process both text and images:

```python
from litellm import completion

response = completion(
    model="xai/grok-vision-beta",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What do you see in this image?"},
                {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
            ]
        }
    ]
)

print(response.choices[0].message.content)
```

## Function Calling

Grok models support function calling for enhanced capabilities:

```python
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_current_time",
            "description": "Get the current time in a specific timezone",
            "parameters": {
                "type": "object",
                "properties": {
                    "timezone": {
                        "type": "string",
                        "description": "The timezone to get the time for",
                    }
                },
                "required": ["timezone"],
            },
        },
    }
]

response = completion(
    model="xai/grok-beta",
    messages=[{"role": "user", "content": "What time is it in Tokyo right now?"}],
    tools=tools,
)
```

## Advanced Features

### Temperature and Creativity Control

Control the creativity of Grok's responses:

```python