xai_client

Classes

XAIClient([api_key, chat_completion_parser, ...])

xAI's client is built on top of OpenAIClient without overriding any methods.

class XAIClient(api_key: str | None = None, chat_completion_parser: Callable[[Completion], Any] = None, input_type: Literal['text', 'messages'] = 'text', base_url: str = 'https://api.x.ai/v1', env_api_key_name: str = 'XAI_API_KEY')[source]

Bases: OpenAIClient

xAI’s client is built on top of OpenAIClient without overriding any methods.

References

Example usage with the AdalFlow Generator:

from adalflow.core import Generator
from adalflow.components.model_client.xai_client import XAIClient
from adalflow.utils import setup_env

setup_env()

generator = Generator(
    model_client=XAIClient(),
    model_kwargs={
        "model": "grok-2-latest",
        "temperature": 0,
        "stream": False,
    }
)

outpupt = generator(prompt_kwargs={"input_str": "Testing. Just say hi and hello world and nothing else."})