Skip to main content
Follow our quickstart guide below or use an interactive notebook.

Installation

To connect to your Kolena Agents using Python, install the kolena-agents client from PyPI using any Python package manager such as pip or poetry:

Initialization

An API Key is required to use the python client. Create and copy a key, then store the value in a KOLENA_API_KEY environment variable:

Usage

Here’s an example of how to use the client to add, download and delete Agent Runs:

Managing Agent Properties

You can attach key-value pairs metadata to your Agents for organizing, filtering, and tracking purposes. Metadata values can be primitives (strings, numbers, booleans, or null) or arrays (lists of primitive values). See the API reference for more details.

Synchronous Usage

You can also add an Agent Run synchronously, which creates a Run and waits for processing of all prompts to complete. Note that this endpoint has rate limits.

Download Templated Output

When an Agent has an Output Template configured, Runs can be downloaded into the Template.

Query Access Logs

This is available on the Enterprise Plan. Contact Kolena if you’re not on an Enterprise plan but would like to try this feature.

View Credit History

Pull credit history to get insights on usage. See the API reference for more details.

Manage API Keys

Programmatically manage API keys for automated rotation and monitoring. See the API reference reference for more details.

Serializing to JSON

All kolena-agents objects are standard Pydantic data objects and can be easily converted to and from JSON:

Timeouts and Retries

By default the client waits up to 10 minutes for a response, and retries failed requests up to 3 times with exponential backoff. Connection errors, dropped connections and transient HTTP statuses (408, 429, 500, 502, 503, 504) are retried automatically for idempotent requests. Connections that cannot be established normally fail after 5 seconds so they are retried promptly rather than hanging. The timeout applies to each network operation rather than to the request as a whole, so a large upload that is still making progress will not time out. Streaming uploads use the operation timeout while connecting and sending so the shorter connection timeout cannot interrupt the request body.
add_wait is the one exception: the server holds the connection open for the poll window you request, so the client never gives up before that deadline even if you set a shorter timeout.
Requests that create or modify data, such as agent_run.add, are retried only when it is certain the server did not act on them: failures before the request reaches the server, and responses (408, 429) where the server rejected the request without processing it. They are not retried if the connection drops after the request was sent, or on 500/502/503/504, since the server may have already applied the request.

Webhook

Kolena provides a helper function to handle signature verification and parsing. See Webhook Integration for more information.

Supported Python Versions

Python versions 3.8 and later are supported.