Chromia
Start Building

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.

Default option: xAI

  1. Open the xAI API page.

  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
    XAI_API_KEY=your_api_key_here

When this is done, go to Test your setup.

Alternative option: Groq

  1. Open the Groq console.

  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
    XAI_API_KEY=your_api_key_here
  5. In /agent/services/openai.ts, change the baseURL to:

    typescript
    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
    model: "llama-3.1-8b-instant"

    agent/tools/memory.ts example:

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

    The Groq model list shows which models you can use.

Once these changes are in place, go to 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
    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.