Metadata-Version: 2.1
Name: cursor-sdk
Version: 1.4.2
Summary: Python client for the Cursor SDK bridge.
Author: Cursor
License: Proprietary
Project-URL: Homepage, https://cursor.com
Project-URL: Documentation, https://cursor.com/docs/sdk/python
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: httpx <1,>=0.27
Provides-Extra: test
Requires-Dist: packaging >=24 ; extra == 'test'
Requires-Dist: pytest-asyncio >=0.23 ; extra == 'test'
Requires-Dist: pytest >=8 ; extra == 'test'

# cursor-sdk

Python SDK for Cursor agents — script the same agent that runs in the Cursor IDE, CLI, and web app, with sync and async clients.

Docs and quickstart: https://cursor.com/docs/sdk/python

## Shared SDK version

Starting with `1.0.24`, the Python package and `@cursor/sdk` use the same
version and are built from the same commit. Python therefore jumps directly
from `0.1.9` to `1.0.24`; there are no missing Python releases in between.
The alignment does not change the Python SDK's public-beta status.

## Install

```bash
pip install cursor-sdk
```

Requires Python 3.10+. Wheels are published for macOS (arm64, x64), Linux (arm64, x64), and Windows (x64).

## Notices and bridge diagnostics

The SDK runs a local bridge process. Lines the bridge addresses to you start
with `[cursor-sdk]`. They are written to your process's stderr, each distinct
line once. Everything else the bridge writes to its stderr goes to the
`cursor_sdk.bridge` logger at `DEBUG`; set `CURSOR_SDK_LOG=debug` to see it.

## No-repo cloud agents

Cloud agents can run on an empty VM with no repository. Pass `cloud` and leave
repos unset:

```python
agent = client.agents.create(cloud=CloudAgentOptions(repos=[]))
```

No-repo agents must be enabled for your account or team, and repository-scoped
API keys cannot create them. See [`examples/no_repo_cloud_agent.py`](./examples/no_repo_cloud_agent.py).

For cloud agents, `agent.get_usage()` returns billed token usage and dollar
cost per run. Cost is server-derived from Cursor's billing pipeline
(discounts included, never estimated client-side) and eventually consistent
shortly after a run ends. Local agents are not supported yet.

For local agents, `agent.summarize()` condenses the conversation now instead
of waiting for the context limit, the same action as the CLI's `/summarize`.
It returns a `Run` like `send()`: `run.wait().result` holds the summary text,
and the stream yields `SDKSummaryMessage` updates. It raises
`ConfigurationError` on cloud agents, and `BadRequestError` before the
agent's first send has saved a conversation.

```python
run = agent.summarize()
print(run.wait().result)
```

## Steer a running run

`send()` raises `AgentBusyError` while an agent has an active run.
`run.steer(text)` sends the text into that run instead, on local and cloud
runs, sync and async:

```python
from cursor_sdk import SteerQueued

outcome = run.steer("Also cover the error path")
if outcome == "complete_delivered":
    pass  # The run has the text.
elif outcome == "revert_to_followup":
    pass  # Nothing took the text. Send it as a follow-up.
elif isinstance(outcome, SteerQueued):
    # The text is already queued. Do not send it again.
    if outcome.run is not None:
        outcome.run.wait()
```

When a cloud run is no longer active, the server queues the text as the
follow-up that starts the next run, and `outcome.run` is that run. A server
that does not name the run returns `SteerQueued(run=None)`; the text is still
queued. A resend
sends the text twice, or raises `AgentBusyError` while the queued run is
active. A steer is never retried. It raises `NetworkError` when the request
fails or the bridge answers 5xx, `APITimeoutError` on a timeout,
`RateLimitError` on a rate limit, `BadRequestError` when the agent cannot take
it (for example an archived agent), and `FeatureUnavailableError` when the
account has no steering. After any of these except `RateLimitError` the outcome
is unknown, so the error is not retryable (`is_retryable` is `False`): check the
run's or agent's state instead of resending. A `RateLimitError` means the steer
was not delivered; it is safe to send again later.

## Local agents on networks that block HTTP/2

Local agent streams use HTTP/2. When a proxy or firewall blocks that protocol,
a run reaches `RUNNING` and then ends with `Protocol error`. Catalog calls
such as `Cursor.models.list()` still succeed, and the Cursor app on the same
machine keeps working.

Switch local agent streams to HTTP/1.1 before the SDK launches its bridge,
which is before `Client.launch_bridge()`, `AsyncClient.launch_bridge()`, or
the first call that uses the default client:

```python
from cursor_sdk import Client, Cursor

Cursor.configure(local={"use_http1_for_agent": True})

with Client.launch_bridge() as client:
    ...
```

`AsyncCursor.configure` takes the same argument. Set
`CURSOR_SDK_USE_HTTP1_FOR_AGENT=1` before the process starts when the call
site cannot change. A bridge reads the setting once, when it starts, so
`configure` raises `ConfigurationError` while a bridge the SDK launched is
still running. Close that client, or call `close_default_client()` for the
default one, then configure again.

> Public beta. APIs may change before general availability.
