---
title: "Semantic Kernel (gateway)"
description: "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.

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the Semantic Kernel integration.
Follow https://www.respan.ai/docs/integrations/gateway/semantic-kernel.md
```

## Setup

<Steps>
<Step title="Install packages">

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

</Step>

<Step title="Set environment variables">

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

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

</Step>

<Step title="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://gateway.respan.ai"),
)
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())
```

</Step>
</Steps>

## 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).
