Semantic Kernel (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

1

Install packages

$pip install semantic-kernel openai
2

Set environment variables

$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.

3

Point Semantic Kernel to the Respan gateway

1import asyncio
2import os
3
4from openai import AsyncOpenAI
5from semantic_kernel import Kernel
6from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
7from semantic_kernel.connectors.ai.open_ai import OpenAIChatPromptExecutionSettings
8from semantic_kernel.functions import KernelArguments
9
10kernel = Kernel()
11client = AsyncOpenAI(
12 api_key=os.environ["RESPAN_API_KEY"],
13 base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
14)
15kernel.add_service(
16 OpenAIChatCompletion(
17 service_id="chat",
18 ai_model_id=os.getenv("RESPAN_MODEL", "gpt-5-mini"),
19 async_client=client,
20 )
21)
22
23async def main() -> None:
24 result = await kernel.invoke_prompt(
25 "Say hello through the Respan gateway.",
26 arguments=KernelArguments(
27 settings=OpenAIChatPromptExecutionSettings(
28 service_id="chat",
29 temperature=0.2,
30 max_tokens=80,
31 )
32 ),
33 )
34 print(result)
35
36asyncio.run(main())

Switch models

Change RESPAN_MODEL to another model available in your Respan account.

$export RESPAN_MODEL="gpt-5.5"
$export RESPAN_MODEL="gpt-5-mini"

See the full model list.