Basic Agent with Streaming

Code

1from kern.agent import Agent
2from kern.models.portkey import Portkey
3
4agent = Agent(
5 model=Portkey(
6 id="@first-integrati-707071/gpt-5-nano",
7 ),
8 markdown=True,
9)
10
11# Print the response in the terminal
12agent.print_response(
13 "What is Portkey and why would I use it as an AI gateway?", stream=True
14)

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API keys

1export PORTKEY_API_KEY=***
2export PORTKEY_VIRTUAL_KEY=***

Install dependencies

1uv pip install -U kern-ai

Run Agent

1python cookbook/11_models/portkey/basic_stream.py