Skip to content
This documentation covers the kagent 1.0 alpha. For the latest 0.x release, see the 0.x docs.

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

xAI

Page as Markdown

Configure kagent to use xAI Grok models through xAI’s OpenAI-compatible API.

xAI’s Grok models are served through an OpenAI-compatible API, so a ModelConfigModelConfigA Kubernetes custom resource naming one model at one provider, along with the credentials to reach it. An AgentTemplate references one by name, and every agent compiled from that template calls the model that it names.Learn more for xAI sets provider: OpenAI and points openAI.baseUrl at xAI. There is no separate xAI provider value.

Create the ModelConfig

  1. Save your xAI API key as an environment variable.

    export XAI_API_KEY=<your_api_key>
  2. Create a Kubernetes Secret that stores the API key. Create it in the same namespace as the AgentTemplates that use it, such as kagent.

    kubectl create secret generic kagent-xai -n kagent --from-literal XAI_API_KEY=$XAI_API_KEY
  3. Create a ModelConfig that references the Secret and sets the xAI base URL.

    kubectl apply -f - <<EOF
    apiVersion: kagent.dev/v1alpha3
    kind: ModelConfig
    metadata:
      name: grok-model-config
      namespace: kagent
    spec:
      apiKeySecret: kagent-xai
      apiKeySecretKey: XAI_API_KEY
      model: grok-3
      provider: OpenAI
      openAI:
        baseUrl: https://api.x.ai/v1
    EOF
    FieldDescription
    apiKeySecretThe name of the Kubernetes Secret that stores the API key, in the same namespace as this ModelConfig.
    apiKeySecretKeyThe key within that Secret that holds the API key.
    modelThe Grok model to use. For the available models, see the xAI model docs.
    providerThe provider to use, OpenAI. xAI is reached through the OpenAI provider.
    openAI.baseUrlThe xAI API endpoint, https://api.x.ai/v1.

For the rest of the settings that the openAI block accepts, see OpenAI. For every openAI field, including its type, default, and validation rules, see the API reference.

Use the ModelConfig

Reference the ModelConfig by name from an AgentTemplate in the same namespace.

spec:
  modelConfig:
    name: grok-model-config

Next steps