You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplify Python Client page: trim features, reorder use cases
Remove verbose usage examples (reference client README instead),
simplify feature list, move Data Apps above CLI use case, and
clarify Python/JS Data Apps availability.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@@ -11,12 +11,10 @@ The [Kai Python Client](https://github.com/keboola/kai-client) is an official Py
11
11
## Features
12
12
13
13
-**Command-line interface** for quick interactions without writing code
14
-
-**Async/await support** using `httpx`
15
-
-**Server-Sent Events (SSE) streaming** for real-time chat responses
16
-
-**Type-safe models** with Pydantic v2
17
-
-**Comprehensive error handling** with custom exception classes
18
-
-**Session management** for chat conversations
19
-
-**Full API coverage** including chat, history, and voting endpoints
14
+
-**Real-time streaming** — see responses as they arrive
15
+
-**Conversation management** — maintain context across multiple messages
16
+
-**Tool approval flows** — review and approve Kai actions programmatically
17
+
-**Full API coverage** — chat, history, and feedback
20
18
21
19
## Installation
22
20
@@ -95,120 +93,44 @@ In interactive mode, type your messages and press Enter. Type `exit`, `quit`, or
95
93
96
94
**Tool approval:** When Kai calls a write tool (e.g., `update_descriptions`, `run_job`, `create_config`), the CLI pauses and asks you to approve or deny. Use `--auto-approve` to skip this prompt.
97
95
98
-
## Usage Examples
96
+
For more usage examples (non-streaming chat, conversations, tool calls, tool approval, error handling), see the [client README](https://github.com/keboola/kai-client#readme).
99
97
100
-
### Simple Chat (Non-Streaming)
98
+
##Use Cases
101
99
102
-
```python
103
-
asyncwith KaiClient(
104
-
storage_api_token="your-master-token",
105
-
storage_api_url="https://connection.keboola.com"
106
-
) as client:
107
-
chat_id, response =await client.chat("What is 2 + 2?")
108
-
print(response)
109
-
```
100
+
### Integrating Kai into Data Apps
110
101
111
-
### Continuing a Conversation
102
+
The Kai Python Client can be embedded into Keboola [Data Apps](/data-apps/) to provide AI-powered chat interfaces for your end users.
112
103
113
-
```python
114
-
asyncwith KaiClient(
115
-
storage_api_token="your-master-token",
116
-
storage_api_url="https://connection.keboola.com"
117
-
) as client:
118
-
chat_id = client.new_chat_id()
119
-
120
-
# First message
121
-
asyncfor event in client.send_message(chat_id, "Hello!"):
122
-
if event.type =="text":
123
-
print(event.text, end="")
124
-
print()
125
-
126
-
# Continue the conversation (reuse same chat_id)
127
-
asyncfor event in client.send_message(chat_id, "What did I just say?"):
128
-
if event.type =="text":
129
-
print(event.text, end="")
130
-
print()
131
-
```
104
+
#### Python/JS Data Apps
132
105
133
-
### Handling Tool Calls
106
+
You can integrate Kai into [Python/JS Data Apps](/data-apps/python-js/) today using the Kai Python Client directly. A dedicated plugin with ready-made patterns will be available soon to simplify the setup.
134
107
135
-
```python
136
-
asyncwith KaiClient(
137
-
storage_api_token="your-master-token",
138
-
storage_api_url="https://connection.keboola.com"
139
-
) as client:
140
-
chat_id = client.new_chat_id()
141
-
142
-
asyncfor event in client.send_message(chat_id, "List my Keboola tables"):
143
-
match event.type:
144
-
case"text":
145
-
print(event.text, end="")
146
-
case"tool-call":
147
-
if event.state =="input-available":
148
-
print(f"\n[Calling {event.tool_name} with {event.input}]")
Some tools require explicit approval before execution. The server sends a `tool-approval-request` event with an `approval_id` that you use to approve or reject.
110
+
The [kai-streamlit plugin](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) provides patterns and working code for building [Streamlit Data Apps](/data-apps/streamlit/) with an integrated Kai chat interface. It handles the async bridge between Streamlit's synchronous model and the KaiClient's async API, streaming responses into Streamlit containers, toolapproval flows with interactive Approve/Deny buttons, and session state management across Streamlit reruns.
158
111
159
-
```python
160
-
from kai_client import KaiClient
112
+
To get started, install the dependencies:
161
113
162
-
asyncwith KaiClient(
163
-
storage_api_token="your-master-token",
164
-
storage_api_url="https://connection.keboola.com"
165
-
) as client:
166
-
chat_id = client.new_chat_id()
167
-
pending_approval_id =None
168
-
169
-
asyncfor event in client.send_message(chat_id, "Create a new bucket"):
170
-
if event.type =="tool-approval-request":
171
-
pending_approval_id = event.approval_id
172
-
173
-
# Approve the pending tool
174
-
if pending_approval_id:
175
-
asyncfor event in client.approve_tool(
176
-
chat_id=chat_id,
177
-
approval_id=pending_approval_id,
178
-
):
179
-
if event.type =="text":
180
-
print(event.text, end="")
114
+
```bash
115
+
pip install kai-client streamlit
181
116
```
182
117
183
-
### Error Handling
118
+
Then use the `run_async` bridge pattern to call KaiClient from Streamlit:
184
119
185
120
```python
186
-
from kai_client import (
187
-
KaiClient,
188
-
KaiError,
189
-
KaiAuthenticationError,
190
-
KaiRateLimitError,
191
-
KaiNotFoundError,
192
-
)
193
-
194
-
asyncwith KaiClient(
195
-
storage_api_token="your-master-token",
196
-
storage_api_url="https://connection.keboola.com"
197
-
) as client:
121
+
import asyncio
122
+
from kai_client import KaiClient
123
+
124
+
defrun_async(coro):
125
+
"""Run an async coroutine from sync Streamlit code."""
126
+
loop = asyncio.new_event_loop()
198
127
try:
199
-
asyncfor event in client.send_message("chat-id", "Hello"):
200
-
print(event)
201
-
except KaiAuthenticationError:
202
-
print("Authentication failed")
203
-
except KaiRateLimitError:
204
-
print("Rate limited, try again later")
205
-
except KaiNotFoundError:
206
-
print("Chat not found")
207
-
except KaiError as e:
208
-
print(f"API error: {e.code} - {e.message}")
128
+
return loop.run_until_complete(coro)
129
+
finally:
130
+
loop.close()
209
131
```
210
132
211
-
## Use Cases
133
+
See the [plugin repository](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) for a complete working example with streaming, tool approval, and suggested action buttons.
Once installed, ask Claude to "use kai" or "help me with kai cli" to activate the skill. Claude can then run `kai chat`, `kai history`, `kai ping`, and other CLI commands on your behalf.
236
158
237
-
### Integrating Kai into Data Apps
238
-
239
-
The Kai Python Client can be embedded into Keboola [Data Apps](/data-apps/) to provide AI-powered chat interfaces for your end users.
240
-
241
-
#### Streamlit Data Apps
242
-
243
-
The [kai-streamlit plugin](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) provides patterns and working code for building [Streamlit Data Apps](/data-apps/streamlit/) with an integrated Kai chat interface. It handles the async bridge between Streamlit's synchronous model and the KaiClient's async API, streaming responses into Streamlit containers, tool approval flows with interactive Approve/Deny buttons, and session state management across Streamlit reruns.
244
-
245
-
To get started, install the dependencies:
246
-
247
-
```bash
248
-
pip install kai-client streamlit
249
-
```
250
-
251
-
Then use the `run_async` bridge pattern to call KaiClient from Streamlit:
252
-
253
-
```python
254
-
import asyncio
255
-
from kai_client import KaiClient
256
-
257
-
defrun_async(coro):
258
-
"""Run an async coroutine from sync Streamlit code."""
259
-
loop = asyncio.new_event_loop()
260
-
try:
261
-
return loop.run_until_complete(coro)
262
-
finally:
263
-
loop.close()
264
-
```
265
-
266
-
See the [plugin repository](https://github.com/keboola/kai-client/tree/main/plugins/kai-streamlit) for a complete working example with streaming, tool approval, and suggested action buttons.
267
-
268
-
#### Python/JS Data Apps
269
-
270
-
Support for integrating Kai into [Python/JS Data Apps](/data-apps/python-js/) is coming soon. A dedicated plugin will be available to simplify embedding Kai chat into custom Python and JavaScript-based data applications.
0 commit comments