Authentication
Set yourXAI_API_KEY environment variable. You can get one from xAI here.
Example
UsexAI with your Agent:
Params
For more information, please refer to the xAI docs as well.Params
xAI also supports the params of OpenAI.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
XAI_API_KEY environment variable. You can get one from xAI here.
export XAI_API_KEY=sk-***
setx XAI_API_KEY sk-***
xAI with your Agent:
from phi.agent import Agent, RunResponse
from phi.model.xai import xAI
agent = Agent(
model=xAI(id="grok-beta"),
markdown=True
)
# Get the response in a variable
# run: RunResponse = agent.run("Share a 2 sentence horror story.")
# print(run.content)
# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story.")
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | "grok-beta" | The specific model ID used for generating responses. |
name | str | "xAI" | The name identifier for the xAI agent. |
provider | str | "xAI" | The provider of the model, combining "xAI" with the model ID. |
api_key | Optional[str] | - | The API key for authenticating requests to the xAI service. Retrieved from the environment variable XAI_API_KEY. |
base_url | str | "https://api.xai.xyz/v1" | The base URL for making API requests to the xAI service. |
Was this page helpful?