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

# Using OpenAI SDK

> How to use VoidAI with the official OpenAI SDKs

VoidAI is fully compatible with the OpenAI SDK. You can use all the features you're familiar with by simply changing the base URL and API key.

## Installation

<CodeGroup>
  ```bash Python theme={null}
  pip install openai
  ```

  ```bash Node.js theme={null}
  npm install openai
  ```
</CodeGroup>

## Configuration

The only changes needed are:

1. Set `base_url` / `baseURL` to `https://api.voidai.app/v1`
2. Use your VoidAI API key instead of OpenAI's

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

  client = OpenAI(
      api_key="sk-voidai-your_key_here",
      base_url="https://api.voidai.app/v1"
  )
  ```

  ```typescript TypeScript theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    apiKey: 'sk-voidai-your_key_here',
    baseURL: 'https://api.voidai.app/v1'
  });
  ```
</CodeGroup>

## Supported Features

### Chat Completions

Full support for chat completions including streaming, function calling, and tool use.

<CodeGroup>
  ```python Python theme={null}
  # Basic completion
  response = client.chat.completions.create(
      model="gpt-5.1",
      messages=[{"role": "user", "content": "Hello!"}]
  )

  # Streaming
  stream = client.chat.completions.create(
      model="gpt-5.1",
      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="")
  ```

  ```typescript TypeScript theme={null}
  // Basic completion
  const response = await client.chat.completions.create({
    model: 'gpt-5.1',
    messages: [{ role: 'user', content: 'Hello!' }]
  });

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

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

### Function Calling / Tools

<CodeGroup>
  ```python Python theme={null}
  tools = [
      {
          "type": "function",
          "function": {
              "name": "get_weather",
              "description": "Get the current weather in a location",
              "parameters": {
                  "type": "object",
                  "properties": {
                      "location": {
                          "type": "string",
                          "description": "The city and state, e.g. San Francisco, CA"
                      }
                  },
                  "required": ["location"]
              }
          }
      }
  ]

  response = client.chat.completions.create(
      model="gpt-5.1",
      messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
      tools=tools,
      tool_choice="auto"
  )

  # Check if a tool was called
  if response.choices[0].message.tool_calls:
      tool_call = response.choices[0].message.tool_calls[0]
      print(f"Function: {tool_call.function.name}")
      print(f"Arguments: {tool_call.function.arguments}")
  ```

  ```typescript TypeScript theme={null}
  const tools = [
    {
      type: 'function' as const,
      function: {
        name: 'get_weather',
        description: 'Get the current weather in a location',
        parameters: {
          type: 'object',
          properties: {
            location: {
              type: 'string',
              description: 'The city and state, e.g. San Francisco, CA'
            }
          },
          required: ['location']
        }
      }
    }
  ];

  const response = await client.chat.completions.create({
    model: 'gpt-5.1',
    messages: [{ role: 'user', content: "What's the weather in Tokyo?" }],
    tools,
    tool_choice: 'auto'
  });

  // Check if a tool was called
  if (response.choices[0].message.tool_calls) {
    const toolCall = response.choices[0].message.tool_calls[0];
    console.log(`Function: ${toolCall.function.name}`);
    console.log(`Arguments: ${toolCall.function.arguments}`);
  }
  ```
</CodeGroup>

### Image Generation

<CodeGroup>
  ```python Python theme={null}
  response = client.images.generate(
      model="gpt-image-1",
      prompt="A sunset over mountains",
      size="1024x1024",
      n=1
  )

  image_url = response.data[0].url
  print(image_url)
  ```

  ```typescript TypeScript theme={null}
  const response = await client.images.generate({
    model: 'gpt-image-1',
    prompt: 'A sunset over mountains',
    size: '1024x1024',
    n: 1
  });

  const imageUrl = response.data[0].url;
  console.log(imageUrl);
  ```
</CodeGroup>

### Audio Transcription

<CodeGroup>
  ```python Python theme={null}
  with open("audio.mp3", "rb") as audio_file:
      transcript = client.audio.transcriptions.create(
          model="whisper-1",
          file=audio_file
      )

  print(transcript.text)
  ```

  ```typescript TypeScript theme={null}
  import fs from 'fs';

  const transcript = await client.audio.transcriptions.create({
    model: 'whisper-1',
    file: fs.createReadStream('audio.mp3')
  });

  console.log(transcript.text);
  ```
</CodeGroup>

### Text-to-Speech

<CodeGroup>
  ```python Python theme={null}
  response = client.audio.speech.create(
      model="tts-1",
      voice="alloy",
      input="Hello, this is a test of text to speech."
  )

  response.stream_to_file("output.mp3")
  ```

  ```typescript TypeScript theme={null}
  const response = await client.audio.speech.create({
    model: 'tts-1',
    voice: 'alloy',
    input: 'Hello, this is a test of text to speech.'
  });

  const buffer = Buffer.from(await response.arrayBuffer());
  fs.writeFileSync('output.mp3', buffer);
  ```
</CodeGroup>

### Embeddings

<CodeGroup>
  ```python Python theme={null}
  response = client.embeddings.create(
      model="text-embedding-3-small",
      input="Your text to embed"
  )

  embedding = response.data[0].embedding
  print(f"Embedding dimension: {len(embedding)}")
  ```

  ```typescript TypeScript theme={null}
  const response = await client.embeddings.create({
    model: 'text-embedding-3-small',
    input: 'Your text to embed'
  });

  const embedding = response.data[0].embedding;
  console.log(`Embedding dimension: ${embedding.length}`);
  ```
</CodeGroup>

## Using Different Providers

The main benefit of VoidAI is accessing multiple providers through one SDK. Simply change the model name:

```python theme={null}
# OpenAI
client.chat.completions.create(model="gpt-5.1", ...)

# Anthropic
client.chat.completions.create(model="claude-sonnet-4-5-20250929", ...)

# Google
client.chat.completions.create(model="gemini-3-pro-preview", ...)

# DeepSeek
client.chat.completions.create(model="deepseek-v3", ...)
```

<Info>
  All providers use the same OpenAI-compatible request/response format. No code changes needed beyond the model name.
</Info>

## Environment Variables

For production, use environment variables:

<CodeGroup>
  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      api_key=os.environ["VOIDAI_API_KEY"],
      base_url="https://api.voidai.app/v1"
  )
  ```

  ```typescript TypeScript theme={null}
  const client = new OpenAI({
    apiKey: process.env.VOIDAI_API_KEY,
    baseURL: 'https://api.voidai.app/v1'
  });
  ```
</CodeGroup>
