Skip to main content
The PyPI distribution is papermap-air; the Python import is air. Python 3.10 or newer is required and the SDK is async-native.

AirClient

Use it as an async context manager or call await client.aclose() explicitly.

client.runs.create()

Creates a run. agent_id is required. model_id, input, context, and webhook_url are optional. Returns a Run.

client.runs.get(run_id)

Returns the latest state of a run.

client.runs.wait(run_id, timeout=60, poll_interval=0.2)

Polls until succeeded, failed, or cancelled. Raises RunTimeoutError when the local timeout is reached.

client.runs.stream(run_id, *, after_seq=0, max_retries=3, retry_delay=0.5)

Returns an async iterator of RunEvent objects. It emits existing events after after_seq, continues with live events, and stops after a terminal run_succeeded, run_failed, or run_cancelled event. The SDK reconnects after a temporary stream failure and resumes after the last sequence number it received. max_retries controls the number of reconnect attempts and retry_delay controls the delay between them.

client.runs.cancel(run_id)

Requests cancellation and returns the server response dictionary.

Run

RunEvent

When type is model_output_reset, discard any partial model text already rendered. This event means AIR started another model attempt after a retry or fallback. Terminal run events end the iterator.

@tool

The decorator derives a JSON schema from type annotations. Synchronous tools run in a thread; async tools are awaited. A context parameter receives the run context. Every tool must return a dictionary. Use a separate ToolRegistry when you want explicit isolation instead of the process-wide default registry.

Worker

Important methods are start(), poll_once(), heartbeat(), run(), mount_mcp(), and aclose().

Errors

All SDK errors inherit from AirError:
  • AirProtocolError for rejected or unexpected HTTP responses
  • RunTimeoutError when a local wait deadline expires
  • ToolDefinitionError for invalid or duplicate tool definitions
  • ToolResultError when a tool does not return a dictionary
  • McpError for MCP transport or protocol failures