Integrations

xAI Grok

Build retrieval-augmented generation pipelines by combining Aether's vector search with xAI's Grok models via the OpenAI-compatible API.

Aether handles document storage and semantic retrieval while Grok generates grounded, context-aware answers from the retrieved content. Because xAI exposes an OpenAI-compatible API, you can use the standard OpenAI SDK with a custom base URL.


Prerequisites

Install the Aether SDK alongside the OpenAI SDK.

TypeScript
npm install @aether-ai/sdk openai

OpenAI-compatible API

xAI's API is fully OpenAI-compatible, so you use the OpenAI SDK pointed at https://api.x.ai/v1. No additional xAI-specific SDK is required.

Environment variables

Configuration

Set the following environment variables before running the examples below.

  • XAI_API_KEY — your xAI API key (required).
  • AETHER_API_KEY — your Aether API key, loaded and passed to the client below (optional for unauthenticated deployments).

Full working example

The pattern is straightforward: retrieve relevant documents from Aether, inject them as context into a Grok prompt, and let the model synthesize a grounded answer.

TypeScript
import { AetherClient } from "@aether-ai/sdk";
import OpenAI from "openai";

const aether = new AetherClient({ apiKey: process.env.AETHER_API_KEY });
const results = await aether.retrieve("Can I work remotely full time?", 3);
const context = results.map((r) => `[${r.title ?? r.doc_id}]\n${r.content}`).join("\n\n");

const xai = new OpenAI({
  baseURL: "https://api.x.ai/v1",
  apiKey: process.env.XAI_API_KEY,
});

const response = await xai.chat.completions.create({
  model: "grok-3",
  messages: [
    { role: "system", content: `Answer using only this context:\n\n${context}` },
    { role: "user", content: "Can I work remotely full time?" },
  ],
});

console.log(response.choices[0].message.content);