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

# LLM Models

> Configure and customize LLM models in Marvin

Marvin uses [Pydantic AI](https://github.com/pydantic/pydantic-ai) as its underlying LLM engine, providing a clean, type-safe interface for working with various LLM providers.

## The Default Model

By default, Marvin uses OpenAI's GPT-4o model. To use this default configuration, you only need to set your OpenAI API key:

```bash theme={null}
export OPENAI_API_KEY="your-api-key"
```

## Configuring Models

### Using String Identifiers

The simplest way to specify a model is with a string identifier in the format `provider:model_name`:

```python theme={null}
import marvin

# Create an agent with a specific model
agent = marvin.Agent(model="openai:gpt-4o-mini")
```

### Model Settings

You can customize model behavior using the `model_settings` parameter when creating an agent:

```python theme={null}
import marvin

agent = marvin.Agent(
    name="Creative Writer",
    model="openai:gpt-4o",
    model_settings={
        "temperature": 0.8,

    }
)
```

## Changing the Default Model

You can change the default model for all agents in your application:

```python theme={null}
import marvin

marvin.defaults.model = "openai:gpt-4o-mini"

result = marvin.run("Write a haiku")
```

## Environment Variables

You can also configure the default model and other settings using environment variables:

```bash theme={null}
# Set the default model
export MARVIN_AGENT_MODEL="openai:gpt-4"

# Configure model settings
export MARVIN_AGENT_TEMPERATURE=0.7
```

## Model Providers

Marvin supports any model provider that is compatible with Pydantic AI. Common providers include:

* OpenAI
* Anthropic
* Azure OpenAI
* Google

Each provider may require its own API key and configuration. Refer to the provider's [documentation](https://ai.pydantic.dev/models/) for specific setup instructions.

### Passing Configuration to Models

For more control, you may pass `pydantic-ai` models when creating an agent.

For example, to use Anthropic's Claude 3.5 Sonnet model with a custom `httpx` client:

```bash theme={null}
export ANTHROPIC_API_KEY="your-api-key"
```

```python theme={null}
import os
from pathlib import Path

import httpx
from pydantic_ai.models.anthropic import AnthropicModel
import marvin

def write_file(path: str, content: str):
    """Write content to a file"""
    _path = Path(path)
    _path.write_text(content)

writer = marvin.Agent(
    model=AnthropicModel(
        "anthropic/claude-3-5-sonnet@latest",
        http_client=httpx.AsyncClient(
            timeout=10,
            # proxy="http://localhost:8080",
            headers={"x-api-key": os.getenv("ANTHROPIC_API_KEY", "gonna fail")},
        ),
    ),
    name="Technical Writer",
    instructions="Write concise, engaging content for developers",
    tools=[write_file],
)

result = marvin.run("how to use pydantic? write haiku to docs.md", agents=[writer])
print(result)
```
