# Configure your API key · Build a chat agent on Chromia · Learn Chromia

> The chat agent needs an API key before it can run. Out of the box, the project targets xAI. You can also use Groq or any other API that is compatible with…

Source: https://chromia.com/learn/chat-agent-course/configure-api-key/

Build a chat agent on ChromiaLesson 3 of 5

1. [01Build a chat agent on Chromia](https://chromia.com/learn/chat-agent-course/introduction/)
2. [02Set up your project](https://chromia.com/learn/chat-agent-course/setup/)
3. [03Configure your API key](https://chromia.com/learn/chat-agent-course/configure-api-key/)
4. [04Test your setup](https://chromia.com/learn/chat-agent-course/test-your-setup/)
5. [05Explore and extend](https://chromia.com/learn/chat-agent-course/explore-and-extend/)

[Learn](https://chromia.com/learn/)[Build a chat agent on Chromia](https://chromia.com/learn/chat-agent-course/)

03 / 05Advanced

# Configure your API key

The chat agent needs an API key before it can run. Out of the box, the project targets **`xAI`**. You can also use **`Groq`** or any other API that is compatible with OpenAI.

info

No `.env` file yet? Make one by copying `.env.sample`, then add the API key for your provider.

Confirm that your key is usable

xAI/Grok, Groq and the other providers listed here are independent third-party services. Their availability, prices and free-credit terms may change without notice. The setup works only with an API key that is active and usable right now, whether free or paid.

If the default provider (xAI/Grok) fails for you, choose another supported one, such as Groq, and use the matching steps below.

## Default option: `xAI`

1. Open the [xAI API page](https://x.ai/api).
2. Log in, or register if you don't have an account.
3. Generate an API key.
4. Add these values to your `.env` file:

   plaintext

   ```nolines
   XAI_API_KEY=your_api_key_here
   ```

When this is done, go to [Test your setup](https://chromia.com/learn/chat-agent-course/test-your-setup/).

## Alternative option: `Groq`

1. Open the [Groq console](https://console.groq.com/keys).
2. Log in, or register if you don't have an account.
3. Generate an API key.
4. Add these values to your `.env` file:

   plaintext

   ```nolines
   XAI_API_KEY=your_api_key_here
   ```
5. In `/agent/services/openai.ts`, change the `baseURL` to:

   typescript

   ```nolines
   baseURL: "https://api.groq.com/openai/v1",
   ```
6. Set your model in two places:

   * **`agent/config.yml`**: put your model in the `model` field, for example `llama-3.1-8b-instant`.
   * **`agent/tools/memory.ts`**: put your model in the `model` variable.

   `agent/config.yml` example:

   yaml

   ```nolines
   model: "llama-3.1-8b-instant"
   ```

   `agent/tools/memory.ts` example:

   typescript

   ```nolines
   model: string = "llama-3.1-8b-instant";
   ```

   The [Groq model list](https://console.groq.com/docs/models) shows which models you can use.

Once these changes are in place, go to [Test your setup](https://chromia.com/learn/chat-agent-course/test-your-setup/).

## Using other OpenAI-compatible APIs

1. Get an API key from your provider.
2. Add these values to your `.env` file:

   plaintext

   ```nolines
   XAI_API_KEY=your_api_key_here
   ```
3. In `/agent/services/openai.ts`, set the `baseURL` to your provider's endpoint.
4. Adjust the configuration files, such as `agent/config.yml`, and any hardcoded values, such as the `model` variable in `agent/tools/memory.ts`, so they fit the model and API you are using.

Written for this site from Chromia’s public course. Code samples are the course’s own.

[← Previous**Set up your project**](https://chromia.com/learn/chat-agent-course/setup/)[Next →**Test your setup**](https://chromia.com/learn/chat-agent-course/test-your-setup/)

On this page

* [Default option: xAI](#default-option-xai)
* [Alternative option: Groq](#alternative-option-groq)
* [Using other OpenAI-compatible APIs](#using-other-openai-compatible-apis)
