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

# Semantic Kernel (gateway)

> Set up Semantic Kernel with the Respan gateway.

Route Semantic Kernel chat completions through the Respan gateway to use models and provider credentials configured in Respan. Only your `RESPAN_API_KEY` is needed in the application.

## Setup

#### Install packages

```bash
pip install semantic-kernel openai
```

#### Set environment variables

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export RESPAN_BASE_URL="https://api.respan.ai/api"
export RESPAN_MODEL="gpt-5-mini"
```

No `OPENAI_API_KEY` is needed when the request is routed through the Respan gateway.

#### Point Semantic Kernel to the Respan gateway

```python
import asyncio
import os

from openai import AsyncOpenAI
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
from semantic_kernel.connectors.ai.open_ai import OpenAIChatPromptExecutionSettings
from semantic_kernel.functions import KernelArguments

kernel = Kernel()
client = AsyncOpenAI(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
)
kernel.add_service(
    OpenAIChatCompletion(
        service_id="chat",
        ai_model_id=os.getenv("RESPAN_MODEL", "gpt-5-mini"),
        async_client=client,
    )
)

async def main() -> None:
    result = await kernel.invoke_prompt(
        "Say hello through the Respan gateway.",
        arguments=KernelArguments(
            settings=OpenAIChatPromptExecutionSettings(
                service_id="chat",
                max_tokens=80,
            )
        ),
    )
    print(result)

asyncio.run(main())
```

## Switch models

Change `RESPAN_MODEL` to another model available in your Respan account.

```bash
export RESPAN_MODEL="gpt-5.5"
export RESPAN_MODEL="gpt-5-mini"
```

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