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

# OpenAI SDK

> Use SaveGate with the official OpenAI Python and Node.js SDKs

## Overview

SaveGate is a drop-in replacement for the OpenAI API. Simply change the base URL and API key - no other code changes needed.

## Python SDK

### Installation

```bash theme={null}
pip install openai
```

### Basic Usage

<CodeGroup>
  ```python Chat Completions theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-savegate-xxxxxxxxxxxxx",
      base_url="https://api.savegate.ai/v1"
  )

  response = client.chat.completions.create(
      model="gpt-4",
      messages=[
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Hello!"}
      ]
  )

  print(response.choices[0].message.content)
  ```

  ```python Streaming theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-savegate-xxxxxxxxxxxxx",
      base_url="https://api.savegate.ai/v1"
  )

  stream = client.chat.completions.create(
      model="gpt-4",
      messages=[{"role": "user", "content": "Tell me a story"}],
      stream=True
  )

  for chunk in stream:
      if chunk.choices[0].delta.content:
          print(chunk.choices[0].delta.content, end="")
  ```

  ```python Async theme={null}
  import asyncio
  from openai import AsyncOpenAI

  client = AsyncOpenAI(
      api_key="sk-savegate-xxxxxxxxxxxxx",
      base_url="https://api.savegate.ai/v1"
  )

  async def main():
      response = await client.chat.completions.create(
          model="gpt-4",
          messages=[{"role": "user", "content": "Hello!"}]
      )
      print(response.choices[0].message.content)

  asyncio.run(main())
  ```
</CodeGroup>

## Node.js SDK

### Installation

```bash theme={null}
npm install openai
```

### Basic Usage

<CodeGroup>
  ```javascript Chat Completions theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    apiKey: 'sk-savegate-xxxxxxxxxxxxx',
    baseURL: 'https://api.savegate.ai/v1'
  });

  async function main() {
    const response = await client.chat.completions.create({
      model: 'gpt-4',
      messages: [
        { role: 'system', content: 'You are a helpful assistant.' },
        { role: 'user', content: 'Hello!' }
      ]
    });

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

  main();
  ```

  ```javascript Streaming theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    apiKey: 'sk-savegate-xxxxxxxxxxxxx',
    baseURL: 'https://api.savegate.ai/v1'
  });

  async function main() {
    const stream = await client.chat.completions.create({
      model: 'gpt-4',
      messages: [{ role: 'user', content: 'Tell me a story' }],
      stream: true
    });

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

  main();
  ```
</CodeGroup>

## Use Any Model

Switch between providers seamlessly:

```python theme={null}
# OpenAI
response = client.chat.completions.create(
    model="gpt-4-turbo",
    messages=[{"role": "user", "content": "Hello!"}]
)

# Anthropic
response = client.chat.completions.create(
    model="claude-3-5-sonnet-20241022",
    messages=[{"role": "user", "content": "Hello!"}]
)

# Google
response = client.chat.completions.create(
    model="gemini-1.5-pro",
    messages=[{"role": "user", "content": "Hello!"}]
)
```

<Card title="View All Models" icon="list" href="/concepts/models">
  See the complete list of 50+ supported models
</Card>
