> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://www.respan.ai/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://www.respan.ai/docs/_mcp/server.

# Guardrails (gateway)

> Set up Guardrails AI with the Respan gateway.

Route Guardrails' underlying LLM calls through the Respan gateway to use 1000+ models from different providers. Only your `RESPAN_API_KEY` is needed — no separate provider keys required.

## Setup

#### Install packages

```bash
pip install guardrails-ai openai
```

#### Set environment variables

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export OPENAI_API_KEY="YOUR_RESPAN_API_KEY"
export OPENAI_BASE_URL="https://api.respan.ai/api"
```

No real OpenAI key needed — the Respan gateway handles provider authentication.

#### Run your guard

```python
import os
from typing import Literal

os.environ["OPENAI_API_KEY"] = os.environ["RESPAN_API_KEY"]
os.environ["OPENAI_BASE_URL"] = "https://api.respan.ai/api"

from guardrails import Guard
from pydantic import BaseModel, Field


class SupportReply(BaseModel):
    answer: str = Field(description="Customer-facing answer")
    priority: Literal["low", "medium", "high"] = Field(description="Ticket priority")


guard = Guard.for_pydantic(output_class=SupportReply)

result = guard(
    model="gpt-5-mini",
    messages=[
        {
            "role": "user",
            "content": "Return JSON with answer and priority for a delayed shipment.",
        }
    ],
)
print(result.validated_output)
```

## Switch models

Change the `model` parameter on `guard(...)` to use another OpenAI model through the same gateway-backed endpoint.

```python
result = guard(model="gpt-5-mini", messages=messages)
result = guard(model="gpt-5.5", messages=messages)
```

> **Note**
>
> Guardrails routes through LiteLLM. Bare Claude or Gemini model strings make LiteLLM call those providers directly instead of the Respan OpenAI-compatible gateway, so this page keeps the switch examples to OpenAI models. Use the Respan API or OpenAI SDK gateway pages for provider-neutral Claude and Gemini examples.

See the [full model list](https://platform.respan.ai/platform/models).