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

# Custom Role Map

> Point OpenAIChat at Mistral's base_url and remap the `model` role to `assistant` via role_map.

Use a custom role map with the OpenAIChat class.

```python custom_role_map.py theme={null}
"""This example shows how to use a custom role map with the OpenAIChat class.

This is useful when using a custom model that doesn't support the default role map.

To run this example:
- Set the MISTRAL_API_KEY environment variable.
- Run `uv pip install openai agno` to install dependencies.
"""

from os import getenv

from agno.agent import Agent
from agno.models.openai import OpenAIChat

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

# Using these Mistral model and url as an example.
model_id = "mistral-medium-2505"
base_url = "https://api.mistral.ai/v1"
api_key = getenv("MISTRAL_API_KEY")
mistral_role_map = {
    "system": "system",
    "user": "user",
    "assistant": "assistant",
    "tool": "tool",
    "model": "assistant",
}

# When initializing the model, we pass our custom role map.
model = OpenAIChat(
    id=model_id,
    base_url=base_url,
    api_key=api_key,
    role_map=mistral_role_map,
)

agent = Agent(model=model, markdown=True)

# Running the agent with a custom role map.
res = agent.print_response("Hey, how are you doing?")

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno openai
```

**2. Export your API keys**

```bash Mac/Linux theme={null}
export MISTRAL_API_KEY="your_mistral_api_key_here"
```

```bash Windows theme={null}
$Env:MISTRAL_API_KEY="your_mistral_api_key_here"
```

**3. Run the example**

Save the code above as `custom_role_map.py`, then run:

```bash theme={null}
python custom_role_map.py
```

Full source: [cookbook/90\_models/openai/chat/custom\_role\_map.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/90_models/openai/chat/custom_role_map.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.