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

# Quick Start Guide

> Get started with LiteLLM Proxy in 5 minutes

## Installation

Install LiteLLM with proxy dependencies:

```bash theme={null}
pip install 'litellm[proxy]'
```

## Basic Setup

<Steps>
  <Step title="Create Configuration File">
    Create a `config.yaml` file with your model configurations:

    ```yaml config.yaml theme={null}
    model_list:
      - model_name: gpt-3.5-turbo
        litellm_params:
          model: openai/gpt-3.5-turbo
          api_key: os.environ/OPENAI_API_KEY
      
      - model_name: claude-3-sonnet
        litellm_params:
          model: anthropic/claude-3-5-sonnet-20241022
          api_key: os.environ/ANTHROPIC_API_KEY

    general_settings:
      master_key: sk-1234  # Change this to a secure key
    ```

    <Warning>
      Never commit your `master_key` to version control. Use environment variables in production.
    </Warning>
  </Step>

  <Step title="Set Environment Variables">
    Export your provider API keys:

    ```bash theme={null}
    export OPENAI_API_KEY="sk-..."
    export ANTHROPIC_API_KEY="sk-ant-..."
    ```
  </Step>

  <Step title="Start the Proxy">
    Run the proxy server:

    ```bash theme={null}
    litellm --config config.yaml
    ```

    The proxy will start on `http://0.0.0.0:4000` by default.

    <CodeGroup>
      ```bash Custom Port theme={null}
      litellm --config config.yaml --port 8000
      ```

      ```bash Debug Mode theme={null}
      litellm --config config.yaml --detailed_debug
      ```

      ```bash With Database theme={null}
      export DATABASE_URL="postgresql://user:password@localhost:5432/litellm"
      litellm --config config.yaml
      ```
    </CodeGroup>
  </Step>

  <Step title="Test the Proxy">
    Make a test request using curl:

    ```bash theme={null}
    curl -X POST 'http://localhost:4000/chat/completions' \
      -H 'Content-Type: application/json' \
      -H 'Authorization: Bearer sk-1234' \
      -d '{
        "model": "gpt-3.5-turbo",
        "messages": [
          {"role": "user", "content": "Hello, how are you?"}
        ]
      }'
    ```
  </Step>
</Steps>

## Generate a Virtual Key

Create an API key for your application:

```bash theme={null}
curl -X POST 'http://localhost:4000/key/generate' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer sk-1234' \
  -d '{
    "models": ["gpt-3.5-turbo", "claude-3-sonnet"],
    "max_budget": 10.0,
    "duration": "30d"
  }'
```

Response:

```json theme={null}
{
  "key": "sk-1234567890abcdef",
  "key_name": null,
  "expires": "2024-04-15T10:30:00Z",
  "models": ["gpt-3.5-turbo", "claude-3-sonnet"],
  "max_budget": 10.0
}
```

## Use the Virtual Key

Now use the generated key instead of the master key:

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

  client = openai.OpenAI(
      api_key="sk-1234567890abcdef",
      base_url="http://localhost:4000"
  )

  response = client.chat.completions.create(
      model="gpt-3.5-turbo",
      messages=[{"role": "user", "content": "Hello!"}]
  )
  print(response.choices[0].message.content)
  ```

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

  const client = new OpenAI({
    apiKey: 'sk-1234567890abcdef',
    baseURL: 'http://localhost:4000'
  });

  const response = await client.chat.completions.create({
    model: 'gpt-3.5-turbo',
    messages: [{ role: 'user', content: 'Hello!' }]
  });

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

  ```bash cURL theme={null}
  curl -X POST 'http://localhost:4000/chat/completions' \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer sk-1234567890abcdef' \
    -d '{
      "model": "gpt-3.5-turbo",
      "messages": [{"role": "user", "content": "Hello!"}]
    }'
  ```
</CodeGroup>

## Access the Admin UI

Open your browser to `http://localhost:4000/ui` to access the admin dashboard.

Login with your master key (`sk-1234`) to:

* View all virtual keys
* Create and manage keys
* Monitor usage and spending
* View request logs
* Manage teams and users

## Load Balancing Example

Configure multiple deployments for automatic load balancing:

```yaml config.yaml theme={null}
model_list:
  # OpenAI deployment 1
  - model_name: gpt-4
    litellm_params:
      model: openai/gpt-4
      api_key: os.environ/OPENAI_API_KEY
      rpm: 480

  # OpenAI deployment 2 (backup)
  - model_name: gpt-4
    litellm_params:
      model: openai/gpt-4
      api_key: os.environ/OPENAI_API_KEY_2
      rpm: 480

  # Azure fallback
  - model_name: gpt-4
    litellm_params:
      model: azure/gpt-4
      api_key: os.environ/AZURE_API_KEY
      api_base: os.environ/AZURE_API_BASE
      api_version: "2024-02-15-preview"

router_settings:
  routing_strategy: usage-based-routing-v2
  enable_pre_call_checks: true

litellm_settings:
  num_retries: 3
  context_window_fallbacks: [{"gpt-4": ["claude-3-opus"]}]
```

Now requests to `gpt-4` will automatically load balance across all three deployments, with fallback to Claude if all GPT-4 deployments fail.

## Database Setup (Optional)

For persistent storage of keys, users, and spend data:

<Steps>
  <Step title="Set up PostgreSQL">
    ```bash theme={null}
    # Using Docker
    docker run -d \
      --name litellm-db \
      -e POSTGRES_DB=litellm \
      -e POSTGRES_USER=llmproxy \
      -e POSTGRES_PASSWORD=dbpassword9090 \
      -p 5432:5432 \
      postgres:16
    ```
  </Step>

  <Step title="Configure Database URL">
    ```bash theme={null}
    export DATABASE_URL="postgresql://llmproxy:dbpassword9090@localhost:5432/litellm"
    ```
  </Step>

  <Step title="Enable DB Storage">
    Update your `config.yaml`:

    ```yaml theme={null}
    general_settings:
      master_key: sk-1234
      store_model_in_db: true
      database_url: os.environ/DATABASE_URL
    ```
  </Step>

  <Step title="Start Proxy">
    The proxy will automatically run database migrations on startup:

    ```bash theme={null}
    litellm --config config.yaml
    ```
  </Step>
</Steps>

## Health Check

Verify the proxy is running:

```bash theme={null}
curl http://localhost:4000/health
```

Response:

```json theme={null}
{
  "status": "healthy",
  "db": "connected",
  "cache": "connected",
  "litellm_version": "1.x.x"
}
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Docker Deployment" icon="docker" href="/proxy/docker-deployment">
    Deploy with Docker for production
  </Card>

  <Card title="Configuration Options" icon="gear" href="/proxy/configs">
    Explore all configuration settings
  </Card>

  <Card title="Virtual Keys" icon="key" href="/proxy/virtual-keys">
    Advanced key management
  </Card>

  <Card title="Budget Alerts" icon="bell" href="/proxy/budget-alerts">
    Set up budget monitoring
  </Card>
</CardGroup>

## Common Issues

### Port Already in Use

If port 4000 is already in use, specify a different port:

```bash theme={null}
litellm --config config.yaml --port 8080
```

### API Key Not Found

Make sure environment variables are exported:

```bash theme={null}
echo $OPENAI_API_KEY  # Should show your key
```

### Database Connection Failed

Verify the DATABASE\_URL format:

```bash theme={null}
postgresql://username:password@host:port/database
```
