The Python SDK is a client for the `/v1` API with session handles, streaming, pagination, and typed errors.

## Install

Python 3.10 or newer.

```bash
pip install ellipsis-dev
```

## Start a session

```python
import os

from ellipsis import (
    ClaudeCodeConfig,
    Ellipsis,
    RunBudget,
    SessionConversationConfig,
)

client = Ellipsis(api_key=os.environ["ELLIPSIS_API_TOKEN"])
handle = client.sessions.run(
    claude_code=ClaudeCodeConfig(
        model="claude-opus-5-5",
        prompt="Run the tests and report failures.",
    ),
    environment="api-environment",
    conversation=SessionConversationConfig(interactive=False),
    budget=RunBudget(session=3),
)
ended = handle.wait(timeout=900)
print(ended.status, ended.error)
```

`run` returns a handle while work continues. `wait` polls until the session is `idle` or `closed` and returns how the prompt's message ended (`completed`, `failed`, `stopped`, or `cancelled`), or `None` when the session has no message. A timeout stops waiting and leaves the session running.

Use `sessions.handle(session_id)` to attach to an existing session.

## Continue a conversation

Leave `conversation.interactive` enabled to accept messages:

```python
handle = client.sessions.run(
    claude_code=ClaudeCodeConfig(
        model="claude-opus-5-5",
        prompt="Investigate the failing validation test.",
    ),
    environment="api-environment",
    budget=RunBudget(session=5),
)
handle.wait(timeout=900)
message = handle.send("Add a regression test.", idempotency_key="add-test")
ended = handle.wait(timeout=900)
print(message.id, ended.status)
```

`send` returns the message, and `wait` then waits for it to be answered. The same message key is accepted once per session. A message sent while the agent is working is answered after the one it is on. `handle.stop()` ends the message the agent is on with `stopped` and cancels queued ones. It fails with `409` when the session is `idle` or `closed`.

## Start an agent session

Start an agent session as written:

```python
response = client.agents.start("test-repair")
ended = client.sessions.handle(response.session.id).wait()
print(ended.status, ended.error)
```

Send any field of a session start to replace the agent's value for that session:

```python
response = client.agents.start("test-repair", budget=RunBudget(session=5))
```

Pass `None` to remove the agent's value so its default applies. Leave an argument out to keep the agent's value.

For an agent with an input schema, pass `input`:

```python
response = client.agents.start(
    "classify-change",
    input={"description": "Reject expired reset tokens"},
)
```

## Stream a session

See [Session events](/docs/api/session-events) for every modeled event and complete JSON examples.

```python
import asyncio
import os

from ellipsis import (
    AsyncEllipsis,
    ClaudeCodeConfig,
    SessionConversationConfig,
)

async def main():
    async with AsyncEllipsis(
        api_key=os.environ["ELLIPSIS_API_TOKEN"]
    ) as client:
        handle = await client.sessions.run(
            claude_code=ClaudeCodeConfig(
                model="claude-opus-5-5",
                prompt="Explain how to test a request validator.",
            ),
            conversation=SessionConversationConfig(interactive=False),
        )
        async for record in handle.stream():
            print(record)

asyncio.run(main())
```

Use `AsyncEllipsis` for asynchronous requests and streaming. Complete records persist; partial text deltas are live-only.

## Read results

```python
for record in client.sessions.records(handle.id):
    if record.kind == "platform" and record.record_type == "message_ended":
        print(record.message_id, record.payload.status, record.payload.cost.total)

for session in client.sessions.list(days=7):
    print(session.id, session.status)
```

`records` returns everything that happened in a session, oldest first. That includes the messages sent to it, the platform's own events, and the agent's output. Pass `message_id` to keep one message's records. SDK page iterators fetch every page. For manual pagination, use `items`, `has_more`, and `next_cursor`.

## Errors

```python
from ellipsis import APIError

try:
    client.sessions.get("session_missing")
except APIError as error:
    print(error.status, error.code)
```

The client defaults to a 60-second request timeout and 2 retries for transport errors, `429`, `502`, `503`, and `504`. Configure `timeout` and `max_retries` when creating it. Each session start and message gets its own `idempotency_key` unless you pass one, so a retry never starts a second session or sends a message twice.
