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

# OpenAI API

> Using OpenAI SDK with GAIA

Use GAIA with the official OpenAI SDK (Python or JavaScript).

## Installation

<Tabs>
  <Tab title="JavaScript">
    ```bash theme={null}
        npm install openai
    ```
  </Tab>

  <Tab title="Python">
    ```bash theme={null}
        pip install openai
    ```
  </Tab>
</Tabs>

## Configuration

Point the SDK to GAIA:

<Tabs>
  <Tab title="JavaScript">
    ```typescript theme={null}
        import OpenAI from 'openai';

        const client = new OpenAI({
          baseURL: 'http://localhost:3000/api/v1',
          apiKey: 'gaia_your_api_key'
        });
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
        from openai import OpenAI

        client = OpenAI(
          base_url="http://localhost:3000/api/v1",
          api_key="gaia_your_api_key"
        )
    ```
  </Tab>
</Tabs>

## Usage

Use your project ID as the model:

<Tabs>
  <Tab title="JavaScript">
    ```typescript theme={null}
        const completion = await client.chat.completions.create({
          model: "proj_abc123", // your GAIA project ID
          messages: [
            { role: "user", content: "What's in my knowledge base?" }
          ]
        });

        console.log(completion.choices[0].message.content);
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
        completion = client.chat.completions.create(
          model="proj_abc123",
          messages=[
            {"role": "user", "content": "What's in my knowledge base?"}
          ]
        )

        print(completion.choices[0].message.content)
    ```
  </Tab>
</Tabs>

## Streaming

```typescript theme={null}
const stream = await client.chat.completions.create({
  model: "proj_abc123",
  messages: [{ role: "user", content: "Hello!" }],
  stream: true
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
```

Your agent automatically uses its configured knowledge, tools, and MCPs.

See [API Reference](/api-reference/chat/completions) for all parameters.
