# Python

To get started with Python and AI Gateway, you can either call the
[OpenAI-Compatible](/docs/ai-gateway/sdks-and-apis/openai-compat) or [Anthropic-Compatible](/docs/ai-gateway/sdks-and-apis/anthropic-compat) API directly, or use the
official [OpenAI](https://github.com/openai/openai-python) and [Anthropic](https://github.com/anthropics/anthropic-sdk-python) Python SDKs,
which are covered below.

## Installation

Install your preferred SDK:

#### OpenAI SDK

```bash
pip install openai
```

#### Anthropic SDK

```bash
pip install anthropic
```

## Quick start

#### OpenAI SDK

```python filename="quickstart.py"
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv('AI_GATEWAY_API_KEY'),
    base_url='https://ai-gateway.vercel.sh/v1'
)

response = client.chat.completions.create(
    model='anthropic/claude-sonnet-4.5',
    messages=[
        {'role': 'user', 'content': 'Explain quantum computing in one paragraph.'}
    ]
)

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

#### Anthropic SDK

```python filename="quickstart.py"
import os
import anthropic

client = anthropic.Anthropic(
    api_key=os.getenv('AI_GATEWAY_API_KEY'),
    base_url='https://ai-gateway.vercel.sh'
)

message = client.messages.create(
    model='anthropic/claude-sonnet-4.5',
    max_tokens=1024,
    messages=[
        {'role': 'user', 'content': 'Explain quantum computing in one paragraph.'}
    ]
)

print(message.content[0].text)
```

## Authentication

Both SDKs support the same authentication methods. Use an [API key](/docs/ai-gateway/authentication-and-byok/authentication#api-key) for local development or [OIDC tokens](/docs/ai-gateway/authentication-and-byok/authentication#oidc-token) for Vercel deployments.

```python filename="auth.py"
import os