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

# xAI

> Use your own xAI credits through Keywords AI

<CardGroup cols={1}>
  <Card title="Get xAI API key" icon="key" href="https://console.x.ai/home">
    Get your xAI API key from the xAI Console to start using xAI models through Keywords AI.
  </Card>
</CardGroup>

## xAI models compatibility

<AccordionGroup>
  <Accordion title="✅ Supported Frameworks">
    * [OpenAI SDK](/integration/development-frameworks/llm_framework/openai/openai-sdk)
    * [LangChain SDK](/integration/development-frameworks/llm_framework/langchain)
    * [Vercel/OpenAI](/integration/development-frameworks/llm_framework/vercel#openai)
    * [Vercel/Google](/integration/development-frameworks/llm_framework/vercel#google)
    * [LlamaIndex SDK](/integration/development-frameworks/llm_framework/llama-index)
    * [Google GenAI](/integration/development-frameworks/llm_framework/google_genai)
    * [Keywords native (Otel)](/get-started/quickstart/gateway)
  </Accordion>

  <Accordion title="❌ Unsupported Frameworks">
    * [Anthropic SDK](/integration/development-frameworks/llm_framework/anthropic)
    * [Vercel/Anthropic](/integration/development-frameworks/llm_framework/vercel#anthropic)
  </Accordion>
</AccordionGroup>

## Add xAI API keys

There are 2 ways to add your xAI credentials to your requests:

### Via UI

<Steps>
  <Step title="Go to the Providers page">
    Go to [Providers page](https://platform.keywordsai.co/platform/api/providers)

    <Frame>
      <img src="https://keywordsai-static.s3.us-east-1.amazonaws.com/docs/settings/providers.jpg" alt="Providers Page" />
    </Frame>
  </Step>

  <Step title="Add your xAI credentials.">
    Follow the on-screen instructions to add your xAI API key.
  </Step>
</Steps>

## Via code

* Add `customer_credentials` parameter in your [request body](/api-endpoints/develop/gateway/chat-completions) to use your own xAI credits.

```json theme={"system"}
{
  // Rest of the request body
  "customer_credentials": {
    "xai": {
      "api_key": "YOUR_XAI_API_KEY"
    }
  }
}
```

## Full request example

<Accordion title="Example">
  <CodeGroup>
    ```python openai_example.py theme={"system"}
    from openai import OpenAI

    client = OpenAI(
        base_url="https://api.keywordsai.co/api/",
        api_key="YOUR_KEYWORDSAI_API_KEY",
    )

    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role":"user", "content":"Tell me a long story"}],
        extra_body={"customer_credentials": {
                      "xai": {
                          "api_key": "YOUR_XAI_API_KEY",
                      }
                    }
                  }
    )
    ```

    ```python api_example.py theme={"system"}
    import requests

    def demo_call(input, 
                  model="gpt-4o",
                  token="YOUR_KEYWORDS_AI_API_KEY"):
        headers = {
            'Content-Type': 'application/json',
            'Authorization': f'Bearer {token}',
        }

        data = {
            'model': model,
            'messages': [{'role': 'user', 'content': input}],
            'customer_credentials': {
                'xai': {
                    'api_key': "YOUR_XAI_API_KEY",
                }
            }
        }

        response = requests.post('https://api.keywordsai.co/api/chat/completions', headers=headers, json=data)
        return response

    messages = "Say 'Hello World'"
    print(demo_call(messages).json())
    ```
  </CodeGroup>
</Accordion>
