airia 0.1.12__py3-none-any.whl → 0.1.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airia/client/async_client.py +97 -3
- airia/client/base_client.py +161 -2
- airia/client/sync_client.py +95 -2
- airia/constants.py +13 -2
- airia/logs.py +1 -23
- airia/types/__init__.py +0 -0
- airia/types/_request_data.py +20 -0
- airia/types/api/__init__.py +9 -1
- airia/types/api/conversations.py +65 -1
- airia/types/api/get_pipeline_config.py +31 -0
- airia/types/api/get_projects.py +44 -0
- airia/types/api/pipeline_execution.py +30 -0
- airia/types/sse/__init__.py +7 -0
- airia/types/sse/sse_messages.py +175 -0
- airia/utils/sse_parser.py +39 -7
- airia-0.1.13.dist-info/METADATA +219 -0
- airia-0.1.13.dist-info/RECORD +24 -0
- airia-0.1.12.dist-info/METADATA +0 -705
- airia-0.1.12.dist-info/RECORD +0 -23
- {airia-0.1.12.dist-info → airia-0.1.13.dist-info}/WHEEL +0 -0
- {airia-0.1.12.dist-info → airia-0.1.13.dist-info}/licenses/LICENSE +0 -0
- {airia-0.1.12.dist-info → airia-0.1.13.dist-info}/top_level.txt +0 -0
airia-0.1.12.dist-info/METADATA
DELETED
|
@@ -1,705 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: airia
|
|
3
|
-
Version: 0.1.12
|
|
4
|
-
Summary: Python SDK for Airia API
|
|
5
|
-
Author-email: Airia LLC <support@airia.com>
|
|
6
|
-
License: MIT
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
15
|
-
Requires-Python: >=3.9
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE
|
|
18
|
-
Requires-Dist: requests>=2.32.3
|
|
19
|
-
Requires-Dist: aiohttp>=3.11.14
|
|
20
|
-
Requires-Dist: loguru>=0.7.3
|
|
21
|
-
Requires-Dist: pydantic>=2.11.0
|
|
22
|
-
Provides-Extra: anthropic
|
|
23
|
-
Requires-Dist: anthropic>=0.49.0; extra == "anthropic"
|
|
24
|
-
Provides-Extra: openai
|
|
25
|
-
Requires-Dist: openai>=1.74.0; extra == "openai"
|
|
26
|
-
Provides-Extra: all
|
|
27
|
-
Requires-Dist: anthropic>=0.49.0; extra == "all"
|
|
28
|
-
Requires-Dist: openai>=1.74.0; extra == "all"
|
|
29
|
-
Dynamic: license-file
|
|
30
|
-
|
|
31
|
-
# Airia Python API Library
|
|
32
|
-
|
|
33
|
-
[](https://badge.fury.io/py/airia)
|
|
34
|
-
[](https://pypi.org/project/airia/)
|
|
35
|
-
[](https://pypi.org/project/airia/)
|
|
36
|
-
|
|
37
|
-
Airia Python API Library that provides a clean and intuitive interface to interact with the Airia AI platform API. The library offers both synchronous and asynchronous clients for maximum flexibility in your applications.
|
|
38
|
-
|
|
39
|
-
## Features
|
|
40
|
-
|
|
41
|
-
- **Dual Client Support**: Choose between synchronous (`AiriaClient`) and asynchronous (`AiriaAsyncClient`) implementations
|
|
42
|
-
- **Pipeline Execution**: Easily run AI pipelines with customizable parameters
|
|
43
|
-
- **Gateway Support**: Seamlessly integrate with OpenAI and Anthropic services through Airia gateways
|
|
44
|
-
- **Error Handling**: Comprehensive error handling with custom exceptions
|
|
45
|
-
- **Logging**: Built-in configurable logging with correlation ID support for request tracing
|
|
46
|
-
- **Flexible Authentication**: Support for both API keys and bearer tokens with flexible configuration
|
|
47
|
-
- **API Key Management**: API key configuration via parameters or environment variables
|
|
48
|
-
- **Bearer Token Support**: Bearer token authentication for ephemeral, short-lived credentials
|
|
49
|
-
|
|
50
|
-
## Installation
|
|
51
|
-
|
|
52
|
-
You can install the package using pip or uv:
|
|
53
|
-
|
|
54
|
-
<table>
|
|
55
|
-
<tr>
|
|
56
|
-
<th>pip</th>
|
|
57
|
-
<th>uv</th>
|
|
58
|
-
</tr>
|
|
59
|
-
<tr>
|
|
60
|
-
<td>
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
pip install airia
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
</td>
|
|
67
|
-
<td>
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
uv add airia
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
</td>
|
|
74
|
-
</tr>
|
|
75
|
-
</table>
|
|
76
|
-
|
|
77
|
-
### Install with optional dependencies
|
|
78
|
-
|
|
79
|
-
The package supports optional dependencies for gateway functionality:
|
|
80
|
-
|
|
81
|
-
<table>
|
|
82
|
-
<tr>
|
|
83
|
-
<th>OpenAI Gateway</th>
|
|
84
|
-
<th>Anthropic Gateway</th>
|
|
85
|
-
<th>All Gateways</th>
|
|
86
|
-
</tr>
|
|
87
|
-
<tr>
|
|
88
|
-
<td>
|
|
89
|
-
|
|
90
|
-
```bash
|
|
91
|
-
pip install "airia[openai]"
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
</td>
|
|
95
|
-
<td>
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
pip install "airia[anthropic]"
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
</td>
|
|
102
|
-
<td>
|
|
103
|
-
|
|
104
|
-
```bash
|
|
105
|
-
pip install "airia[all]"
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
</td>
|
|
109
|
-
</tr>
|
|
110
|
-
</table>
|
|
111
|
-
|
|
112
|
-
### Install with development dependencies
|
|
113
|
-
|
|
114
|
-
Clone the repository:
|
|
115
|
-
|
|
116
|
-
```bash
|
|
117
|
-
git clone https://github.com/AiriaLLC/airia-python.git
|
|
118
|
-
cd airia-python
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
Then, run one of the following commands:
|
|
122
|
-
|
|
123
|
-
<table>
|
|
124
|
-
<tr>
|
|
125
|
-
<th>pip</th>
|
|
126
|
-
<th>uv</th>
|
|
127
|
-
</tr>
|
|
128
|
-
<tr>
|
|
129
|
-
<td>
|
|
130
|
-
|
|
131
|
-
```bash
|
|
132
|
-
pip install dependency-groups
|
|
133
|
-
dev=$(python -m dependency_groups dev)
|
|
134
|
-
pip install -e .
|
|
135
|
-
pip install $dev
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
</td>
|
|
139
|
-
<td>
|
|
140
|
-
|
|
141
|
-
```bash
|
|
142
|
-
uv sync --frozen --group dev
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
</td>
|
|
146
|
-
</tr>
|
|
147
|
-
</table>
|
|
148
|
-
|
|
149
|
-
## Building from Source
|
|
150
|
-
|
|
151
|
-
First make sure you have already cloned the repository, then run one of the following commands:
|
|
152
|
-
|
|
153
|
-
<table>
|
|
154
|
-
<tr>
|
|
155
|
-
<th>pip</th>
|
|
156
|
-
<th>uv</th>
|
|
157
|
-
</tr>
|
|
158
|
-
<tr>
|
|
159
|
-
<td>
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
pip install build
|
|
163
|
-
python -m build
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
</td>
|
|
167
|
-
<td>
|
|
168
|
-
|
|
169
|
-
```bash
|
|
170
|
-
uv build
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
</td>
|
|
174
|
-
</tr>
|
|
175
|
-
</table>
|
|
176
|
-
|
|
177
|
-
This will create both wheel and source distribution in the `dist/` directory.
|
|
178
|
-
|
|
179
|
-
## Quick Start
|
|
180
|
-
|
|
181
|
-
### Client Instantiation
|
|
182
|
-
|
|
183
|
-
```python
|
|
184
|
-
from airia import AiriaClient
|
|
185
|
-
|
|
186
|
-
# API Key Authentication
|
|
187
|
-
client = AiriaClient(
|
|
188
|
-
base_url="https://api.airia.ai", # Default: "https://api.airia.ai"
|
|
189
|
-
api_key=None, # Or set AIRIA_API_KEY environment variable
|
|
190
|
-
timeout=30.0, # Request timeout in seconds (default: 30.0)
|
|
191
|
-
log_requests=False, # Enable request/response logging (default: False)
|
|
192
|
-
custom_logger=None # Use custom logger (default: None - uses built-in)
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
# Bearer Token Authentication
|
|
196
|
-
client = AiriaClient(
|
|
197
|
-
base_url="https://api.airia.ai", # Default: "https://api.airia.ai"
|
|
198
|
-
bearer_token="your_bearer_token", # Must be provided explicitly (no env var fallback)
|
|
199
|
-
timeout=30.0, # Request timeout in seconds (default: 30.0)
|
|
200
|
-
log_requests=False, # Enable request/response logging (default: False)
|
|
201
|
-
custom_logger=None # Use custom logger (default: None - uses built-in)
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
# Convenience method for bearer token
|
|
205
|
-
client = AiriaClient.with_bearer_token(
|
|
206
|
-
bearer_token="your_bearer_token",
|
|
207
|
-
base_url="https://api.airia.ai", # Optional, uses default if not provided
|
|
208
|
-
timeout=30.0, # Optional, uses default if not provided
|
|
209
|
-
log_requests=False, # Optional, uses default if not provided
|
|
210
|
-
custom_logger=None # Optional, uses default if not provided
|
|
211
|
-
)
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
### Synchronous Usage
|
|
215
|
-
|
|
216
|
-
#### With API Key
|
|
217
|
-
|
|
218
|
-
```python
|
|
219
|
-
from airia import AiriaClient
|
|
220
|
-
|
|
221
|
-
# Initialize client (API key can be passed directly or via AIRIA_API_KEY environment variable)
|
|
222
|
-
client = AiriaClient(api_key="your_api_key")
|
|
223
|
-
|
|
224
|
-
# Execute a pipeline
|
|
225
|
-
response = client.execute_pipeline(
|
|
226
|
-
pipeline_id="your_pipeline_id",
|
|
227
|
-
user_input="Tell me about quantum computing"
|
|
228
|
-
)
|
|
229
|
-
|
|
230
|
-
print(response.result)
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
#### With Bearer Token
|
|
234
|
-
|
|
235
|
-
```python
|
|
236
|
-
from airia import AiriaClient
|
|
237
|
-
|
|
238
|
-
# Initialize client with bearer token
|
|
239
|
-
client = AiriaClient.with_bearer_token(bearer_token="your_bearer_token")
|
|
240
|
-
|
|
241
|
-
# Execute a pipeline
|
|
242
|
-
response = client.execute_pipeline(
|
|
243
|
-
pipeline_id="your_pipeline_id",
|
|
244
|
-
user_input="Tell me about quantum computing"
|
|
245
|
-
)
|
|
246
|
-
|
|
247
|
-
print(response.result)
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
#### Synchronous Streaming
|
|
251
|
-
|
|
252
|
-
```python
|
|
253
|
-
from airia import AiriaClient
|
|
254
|
-
|
|
255
|
-
# Initialize client (API key can be passed directly or via AIRIA_API_KEY environment variable)
|
|
256
|
-
client = AiriaClient(api_key="your_api_key")
|
|
257
|
-
# Or with bearer token: client = AiriaClient.with_bearer_token(bearer_token="your_bearer_token")
|
|
258
|
-
|
|
259
|
-
# Execute a pipeline
|
|
260
|
-
response = client.execute_pipeline(
|
|
261
|
-
pipeline_id="your_pipeline_id",
|
|
262
|
-
user_input="Tell me about quantum computing",
|
|
263
|
-
async_output=True
|
|
264
|
-
)
|
|
265
|
-
|
|
266
|
-
for c in response.stream:
|
|
267
|
-
print(c)
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
### Asynchronous Usage
|
|
271
|
-
|
|
272
|
-
#### With API Key
|
|
273
|
-
|
|
274
|
-
```python
|
|
275
|
-
import asyncio
|
|
276
|
-
from airia import AiriaAsyncClient
|
|
277
|
-
|
|
278
|
-
async def main():
|
|
279
|
-
client = AiriaAsyncClient(api_key="your_api_key")
|
|
280
|
-
response = await client.execute_pipeline(
|
|
281
|
-
pipeline_id="your_pipeline_id",
|
|
282
|
-
user_input="Tell me about quantum computing"
|
|
283
|
-
)
|
|
284
|
-
print(response.result)
|
|
285
|
-
|
|
286
|
-
asyncio.run(main())
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
#### With Bearer Token
|
|
290
|
-
|
|
291
|
-
```python
|
|
292
|
-
import asyncio
|
|
293
|
-
from airia import AiriaAsyncClient
|
|
294
|
-
|
|
295
|
-
async def main():
|
|
296
|
-
client = AiriaAsyncClient.with_bearer_token(bearer_token="your_bearer_token")
|
|
297
|
-
response = await client.execute_pipeline(
|
|
298
|
-
pipeline_id="your_pipeline_id",
|
|
299
|
-
user_input="Tell me about quantum computing"
|
|
300
|
-
)
|
|
301
|
-
print(response.result)
|
|
302
|
-
|
|
303
|
-
asyncio.run(main())
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
#### Asynchronous Streaming
|
|
307
|
-
|
|
308
|
-
```python
|
|
309
|
-
import asyncio
|
|
310
|
-
from airia import AiriaAsyncClient
|
|
311
|
-
|
|
312
|
-
async def main():
|
|
313
|
-
client = AiriaAsyncClient(api_key="your_api_key")
|
|
314
|
-
# Or with bearer token: client = AiriaAsyncClient.with_bearer_token(bearer_token="your_bearer_token")
|
|
315
|
-
response = await client.execute_pipeline(
|
|
316
|
-
pipeline_id="your_pipeline_id",
|
|
317
|
-
user_input="Tell me about quantum computing",
|
|
318
|
-
async_output=True
|
|
319
|
-
)
|
|
320
|
-
async for c in response.stream:
|
|
321
|
-
print(c)
|
|
322
|
-
|
|
323
|
-
asyncio.run(main())
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
## Streaming Event Parsing
|
|
327
|
-
|
|
328
|
-
When using streaming mode (`async_output=True`), the API returns Server-Sent Events (SSE) that contain different types of messages throughout the pipeline execution. You can parse and filter these events to extract specific information.
|
|
329
|
-
|
|
330
|
-
### Available Message Types
|
|
331
|
-
|
|
332
|
-
The streaming response includes various message types defined in `airia.types.sse`. Here are the key ones:
|
|
333
|
-
|
|
334
|
-
- `AgentModelStreamFragmentMessage` - Contains actual LLM output chunks
|
|
335
|
-
- `AgentModelStreamStartMessage` - Indicates LLM streaming has started
|
|
336
|
-
- `AgentModelStreamEndMessage` - Indicates LLM streaming has ended
|
|
337
|
-
- `AgentStepStartMessage` - Indicates a pipeline step has started
|
|
338
|
-
- `AgentStepEndMessage` - Indicates a pipeline step has ended
|
|
339
|
-
- `AgentOutputMessage` - Contains step output
|
|
340
|
-
|
|
341
|
-
<details>
|
|
342
|
-
<summary>Click to expand the full list of message types</summary>
|
|
343
|
-
|
|
344
|
-
```python
|
|
345
|
-
[
|
|
346
|
-
AgentPingMessage,
|
|
347
|
-
AgentStartMessage,
|
|
348
|
-
AgentEndMessage,
|
|
349
|
-
AgentStepStartMessage,
|
|
350
|
-
AgentStepHaltMessage,
|
|
351
|
-
AgentStepEndMessage,
|
|
352
|
-
AgentOutputMessage,
|
|
353
|
-
AgentAgentCardMessage,
|
|
354
|
-
AgentDatasearchMessage,
|
|
355
|
-
AgentInvocationMessage,
|
|
356
|
-
AgentModelMessage,
|
|
357
|
-
AgentPythonCodeMessage,
|
|
358
|
-
AgentToolActionMessage,
|
|
359
|
-
AgentModelStreamStartMessage,
|
|
360
|
-
AgentModelStreamEndMessage,
|
|
361
|
-
AgentModelStreamErrorMessage,
|
|
362
|
-
AgentModelStreamUsageMessage,
|
|
363
|
-
AgentModelStreamFragmentMessage,
|
|
364
|
-
AgentAgentCardStreamStartMessage,
|
|
365
|
-
AgentAgentCardStreamErrorMessage,
|
|
366
|
-
AgentAgentCardStreamFragmentMessage,
|
|
367
|
-
AgentAgentCardStreamEndMessage,
|
|
368
|
-
AgentToolRequestMessage,
|
|
369
|
-
AgentToolResponseMessage,
|
|
370
|
-
]
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
</details>
|
|
374
|
-
|
|
375
|
-
### Filtering LLM Output
|
|
376
|
-
|
|
377
|
-
To extract only the actual LLM output text from the stream:
|
|
378
|
-
|
|
379
|
-
```python
|
|
380
|
-
from airia import AiriaClient
|
|
381
|
-
from airia.types import AgentModelStreamFragmentMessage
|
|
382
|
-
|
|
383
|
-
client = AiriaClient(api_key="your_api_key")
|
|
384
|
-
# Or with bearer token: client = AiriaClient.with_bearer_token(bearer_token="your_bearer_token")
|
|
385
|
-
|
|
386
|
-
response = client.execute_pipeline(
|
|
387
|
-
pipeline_id="your_pipeline_id",
|
|
388
|
-
user_input="Tell me about quantum computing",
|
|
389
|
-
async_output=True
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
# Filter and display only LLM output
|
|
393
|
-
for event in response.stream:
|
|
394
|
-
if isinstance(event, AgentModelStreamFragmentMessage) and event.index != -1:
|
|
395
|
-
print(event.content, end="", flush=True)
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
## Pipeline Configuration Retrieval
|
|
399
|
-
|
|
400
|
-
You can retrieve detailed configuration information about a pipeline using the `get_pipeline_config` method:
|
|
401
|
-
|
|
402
|
-
> To get a list of all active pipeline ids, run the `get_active_pipelines_ids` method.
|
|
403
|
-
|
|
404
|
-
```python
|
|
405
|
-
from airia import AiriaClient
|
|
406
|
-
|
|
407
|
-
client = AiriaClient(api_key="your_api_key")
|
|
408
|
-
# Or with bearer token: client = AiriaClient.with_bearer_token(bearer_token="your_bearer_token")
|
|
409
|
-
|
|
410
|
-
# Get pipeline configuration
|
|
411
|
-
config = client.get_pipeline_config(pipeline_id="your_pipeline_id")
|
|
412
|
-
|
|
413
|
-
# Access configuration details
|
|
414
|
-
print(f"Pipeline Name: {config.agent.name}")
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
## Conversation Management
|
|
418
|
-
|
|
419
|
-
You can create and manage conversations using the `create_conversation` method. Conversations allow you to organize and persist interactions within the Airia platform.
|
|
420
|
-
|
|
421
|
-
### Creating Conversations
|
|
422
|
-
|
|
423
|
-
#### Synchronous Usage
|
|
424
|
-
|
|
425
|
-
```python
|
|
426
|
-
from airia import AiriaClient
|
|
427
|
-
|
|
428
|
-
client = AiriaClient(api_key="your_api_key")
|
|
429
|
-
# Or with bearer token: client = AiriaClient.with_bearer_token(bearer_token="your_bearer_token")
|
|
430
|
-
|
|
431
|
-
# Create a basic conversation
|
|
432
|
-
conversation = client.create_conversation(
|
|
433
|
-
user_id="user_123"
|
|
434
|
-
)
|
|
435
|
-
print(f"Created conversation: {conversation.conversation_id}")
|
|
436
|
-
print(f"WebSocket URL: {conversation.websocket_url}")
|
|
437
|
-
|
|
438
|
-
# Create a conversation with all options
|
|
439
|
-
conversation = client.create_conversation(
|
|
440
|
-
user_id="user_123",
|
|
441
|
-
title="My Research Session",
|
|
442
|
-
deployment_id="deployment_456",
|
|
443
|
-
data_source_files={"documents": ["doc1.pdf", "doc2.txt"]},
|
|
444
|
-
is_bookmarked=True
|
|
445
|
-
)
|
|
446
|
-
print(f"Created bookmarked conversation: {conversation.conversation_id}")
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
#### Asynchronous Usage
|
|
450
|
-
|
|
451
|
-
```python
|
|
452
|
-
import asyncio
|
|
453
|
-
from airia import AiriaAsyncClient
|
|
454
|
-
|
|
455
|
-
async def main():
|
|
456
|
-
client = AiriaAsyncClient(api_key="your_api_key")
|
|
457
|
-
# Or with bearer token: client = AiriaAsyncClient.with_bearer_token(bearer_token="your_bearer_token")
|
|
458
|
-
|
|
459
|
-
# Create a basic conversation
|
|
460
|
-
conversation = await client.create_conversation(
|
|
461
|
-
user_id="user_123"
|
|
462
|
-
)
|
|
463
|
-
print(f"Created conversation: {conversation.conversation_id}")
|
|
464
|
-
|
|
465
|
-
# Create a conversation with all options
|
|
466
|
-
conversation = await client.create_conversation(
|
|
467
|
-
user_id="user_123",
|
|
468
|
-
title="My Research Session",
|
|
469
|
-
deployment_id="deployment_456",
|
|
470
|
-
data_source_files={"documents": ["doc1.pdf", "doc2.txt"]},
|
|
471
|
-
is_bookmarked=True
|
|
472
|
-
)
|
|
473
|
-
print(f"Created bookmarked conversation: {conversation.conversation_id}")
|
|
474
|
-
|
|
475
|
-
asyncio.run(main())
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
### Conversation Parameters
|
|
479
|
-
|
|
480
|
-
- **user_id** (required): The unique identifier of the user creating the conversation
|
|
481
|
-
- **title** (optional): A descriptive title for the conversation
|
|
482
|
-
- **deployment_id** (optional): The unique identifier of the deployment to associate with the conversation
|
|
483
|
-
- **data_source_files** (optional): Configuration for data source files to be associated with the conversation
|
|
484
|
-
- **is_bookmarked** (optional): Whether the conversation should be bookmarked (defaults to False)
|
|
485
|
-
- **correlation_id** (optional): A unique identifier for request tracing and logging
|
|
486
|
-
|
|
487
|
-
### Response Fields
|
|
488
|
-
|
|
489
|
-
The `create_conversation` method returns a `CreateConversationResponse` object containing:
|
|
490
|
-
|
|
491
|
-
- **conversation_id**: The unique identifier of the created conversation
|
|
492
|
-
- **user_id**: The user ID associated with the conversation
|
|
493
|
-
- **websocket_url**: The WebSocket URL for real-time communication
|
|
494
|
-
- **deployment_id**: The deployment ID associated with the conversation
|
|
495
|
-
- **icon_id** and **icon_url**: Optional conversation icon information
|
|
496
|
-
- **description**: Optional conversation description
|
|
497
|
-
- **space_name**: Optional workspace or space name
|
|
498
|
-
|
|
499
|
-
## Authentication Methods
|
|
500
|
-
|
|
501
|
-
Airia supports two authentication methods:
|
|
502
|
-
|
|
503
|
-
### API Keys
|
|
504
|
-
- Can be passed as a parameter or via `AIRIA_API_KEY` environment variable
|
|
505
|
-
- Support gateway functionality (OpenAI and Anthropic gateways)
|
|
506
|
-
- Suitable for long-term, persistent authentication
|
|
507
|
-
|
|
508
|
-
### Bearer Tokens
|
|
509
|
-
- Must be provided explicitly (no environment variable fallback)
|
|
510
|
-
- **Important**: Bearer tokens cannot be used with gateway functionality
|
|
511
|
-
- Suitable for ephemeral, short-lived authentication scenarios
|
|
512
|
-
- Ideal for temporary access or programmatic token generation
|
|
513
|
-
|
|
514
|
-
```python
|
|
515
|
-
# ✅ API key with gateway support
|
|
516
|
-
client = AiriaClient.with_openai_gateway(api_key="your_api_key")
|
|
517
|
-
|
|
518
|
-
# ❌ Bearer token with gateway - NOT SUPPORTED
|
|
519
|
-
# client = AiriaClient.with_openai_gateway(bearer_token="token") # This won't work
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
## Gateway Usage
|
|
523
|
-
|
|
524
|
-
Airia provides gateway capabilities for popular AI services like OpenAI and Anthropic, allowing you to use your Airia API key with these services.
|
|
525
|
-
|
|
526
|
-
> **Note**: Gateway functionality requires API key authentication. Bearer tokens are not supported for gateway usage.
|
|
527
|
-
|
|
528
|
-
### OpenAI Gateway
|
|
529
|
-
|
|
530
|
-
```python
|
|
531
|
-
from airia import AiriaClient
|
|
532
|
-
|
|
533
|
-
# Initialize client with OpenAI gateway support
|
|
534
|
-
client = AiriaClient.with_openai_gateway(api_key="your_airia_api_key")
|
|
535
|
-
|
|
536
|
-
# Use OpenAI's API through Airia's gateway
|
|
537
|
-
response = client.openai.chat.completions.create(
|
|
538
|
-
model="gpt-4.1-nano",
|
|
539
|
-
messages=[
|
|
540
|
-
{"role": "system", "content": "You are a helpful assistant."},
|
|
541
|
-
{"role": "user", "content": "Hello!"},
|
|
542
|
-
]
|
|
543
|
-
)
|
|
544
|
-
|
|
545
|
-
print(response.choices[0].message.content)
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
### Anthropic Gateway
|
|
549
|
-
|
|
550
|
-
```python
|
|
551
|
-
from airia import AiriaClient
|
|
552
|
-
|
|
553
|
-
# Initialize client with Anthropic gateway support
|
|
554
|
-
client = AiriaClient.with_anthropic_gateway(api_key="your_airia_api_key")
|
|
555
|
-
|
|
556
|
-
# Use Anthropic's API through Airia's gateway
|
|
557
|
-
response = client.anthropic.messages.create(
|
|
558
|
-
model="claude-3-5-haiku-20241022",
|
|
559
|
-
max_tokens=1000,
|
|
560
|
-
messages=[{"role": "user", "content": "Hello!"}]
|
|
561
|
-
)
|
|
562
|
-
|
|
563
|
-
print(response.content[0].text)
|
|
564
|
-
```
|
|
565
|
-
|
|
566
|
-
You can set the Gateway URL by passing the `gateway_url` parameter when using the gateway constructors. The default values are `https://gateway.airia.ai/openai/v1` for OpenAI and `https://gateway.airia.ai/anthropic` for Anthropic.
|
|
567
|
-
|
|
568
|
-
### Asynchronous Gateway Usage
|
|
569
|
-
|
|
570
|
-
Both gateways also support asynchronous usage:
|
|
571
|
-
|
|
572
|
-
```python
|
|
573
|
-
import asyncio
|
|
574
|
-
from airia import AiriaAsyncClient
|
|
575
|
-
|
|
576
|
-
async def main():
|
|
577
|
-
# Initialize async client with gateway support
|
|
578
|
-
client = AiriaAsyncClient.with_openai_gateway(api_key="your_airia_api_key")
|
|
579
|
-
|
|
580
|
-
# Use OpenAI's API asynchronously through Airia's gateway
|
|
581
|
-
response = await client.openai.chat.completions.create(
|
|
582
|
-
model="gpt-4.1-nano",
|
|
583
|
-
messages=[
|
|
584
|
-
{"role": "system", "content": "You are a helpful assistant."},
|
|
585
|
-
{"role": "user", "content": "Hello!"},
|
|
586
|
-
]
|
|
587
|
-
)
|
|
588
|
-
|
|
589
|
-
print(response.choices[0].message.content)
|
|
590
|
-
|
|
591
|
-
asyncio.run(main())
|
|
592
|
-
```
|
|
593
|
-
|
|
594
|
-
## Advanced Usage
|
|
595
|
-
|
|
596
|
-
### Pipeline Execution with All Options
|
|
597
|
-
|
|
598
|
-
```python
|
|
599
|
-
response = client.execute_pipeline(
|
|
600
|
-
pipeline_id="pipeline_id",
|
|
601
|
-
user_input="Your input text",
|
|
602
|
-
debug=True, # Enable debug mode
|
|
603
|
-
user_id="user_guid", # User identifier
|
|
604
|
-
conversation_id="conversation_guid", # Conversation identifier
|
|
605
|
-
async_output=False, # Stream response (async mode)
|
|
606
|
-
include_tools_response=True, # Return the initial LLM tool result
|
|
607
|
-
images=["base64_encoded_image"], # Include image data
|
|
608
|
-
files=["base64_encoded_file"], # Include file data
|
|
609
|
-
data_source_folders={}, # Data source folders configuration
|
|
610
|
-
data_source_files={}, # Data source files configuration
|
|
611
|
-
in_memory_messages=[ # Context messages for conversation
|
|
612
|
-
{"role": "user", "message": "Previous message"}
|
|
613
|
-
],
|
|
614
|
-
current_date_time="2025-03-26T21:00:00", # Override current date/time
|
|
615
|
-
save_history=True, # Save to conversation history
|
|
616
|
-
additional_info=["extra data"], # Additional metadata
|
|
617
|
-
prompt_variables={"var1": "value1"}, # Variables for prompt templating
|
|
618
|
-
correlation_id="request-123", # Request tracing ID
|
|
619
|
-
api_version="v2" # API version for the request
|
|
620
|
-
)
|
|
621
|
-
```
|
|
622
|
-
|
|
623
|
-
### Configuring Logging
|
|
624
|
-
|
|
625
|
-
```python
|
|
626
|
-
import sys
|
|
627
|
-
from airia import configure_logging
|
|
628
|
-
|
|
629
|
-
# Basic configuration
|
|
630
|
-
logger = configure_logging()
|
|
631
|
-
|
|
632
|
-
# Advanced configuration
|
|
633
|
-
file_logger = configure_logging(
|
|
634
|
-
format_string="[{time:YYYY-MM-DD HH:mm:ss}] [{level}] {message}",
|
|
635
|
-
level="DEBUG",
|
|
636
|
-
sink="app.log",
|
|
637
|
-
rotation="10 MB",
|
|
638
|
-
retention="1 week",
|
|
639
|
-
include_correlation_id=True
|
|
640
|
-
)
|
|
641
|
-
|
|
642
|
-
# Console output with custom format
|
|
643
|
-
console_logger = configure_logging(
|
|
644
|
-
format_string="[{time:HH:mm:ss}] {message}",
|
|
645
|
-
level="INFO",
|
|
646
|
-
sink=sys.stdout
|
|
647
|
-
)
|
|
648
|
-
```
|
|
649
|
-
|
|
650
|
-
## Error Handling
|
|
651
|
-
|
|
652
|
-
The SDK uses custom exceptions to provide clear error messages:
|
|
653
|
-
|
|
654
|
-
```python
|
|
655
|
-
from airia import AiriaAPIError, AiriaClient
|
|
656
|
-
|
|
657
|
-
# Works with both API keys and bearer tokens
|
|
658
|
-
client = AiriaClient(api_key="your_api_key")
|
|
659
|
-
# Or: client = AiriaClient.with_bearer_token(bearer_token="your_bearer_token")
|
|
660
|
-
|
|
661
|
-
try:
|
|
662
|
-
response = client.execute_pipeline(
|
|
663
|
-
pipeline_id="invalid_id",
|
|
664
|
-
user_input="test"
|
|
665
|
-
)
|
|
666
|
-
except AiriaAPIError as e:
|
|
667
|
-
print(f"API error: {e.status_code} - {e.message}")
|
|
668
|
-
```
|
|
669
|
-
|
|
670
|
-
## Requirements
|
|
671
|
-
|
|
672
|
-
- Python 3.9 or higher
|
|
673
|
-
- Core dependencies:
|
|
674
|
-
- requests
|
|
675
|
-
- aiohttp
|
|
676
|
-
- loguru
|
|
677
|
-
- pydantic
|
|
678
|
-
|
|
679
|
-
- Optional dependencies:
|
|
680
|
-
- OpenAI gateway: `openai>=1.74.0`
|
|
681
|
-
- Anthropic gateway: `anthropic>=0.49.0`
|
|
682
|
-
|
|
683
|
-
## Development
|
|
684
|
-
|
|
685
|
-
To run tests (make sure you have development dependencies installed):
|
|
686
|
-
|
|
687
|
-
```bash
|
|
688
|
-
pytest
|
|
689
|
-
```
|
|
690
|
-
|
|
691
|
-
For testing gateway functionality, install the optional dependencies:
|
|
692
|
-
|
|
693
|
-
```bash
|
|
694
|
-
# For OpenAI gateway tests
|
|
695
|
-
pip install -e .[openai]
|
|
696
|
-
pytest tests/test_openai_gateway.py
|
|
697
|
-
|
|
698
|
-
# For Anthropic gateway tests
|
|
699
|
-
pip install -e .[anthropic]
|
|
700
|
-
pytest tests/test_anthropic_gateway.py
|
|
701
|
-
|
|
702
|
-
# For all tests
|
|
703
|
-
pip install -e .[all]
|
|
704
|
-
pytest
|
|
705
|
-
```
|