Skip to main content

Python client wrapper for the Cursor Agent API

Project description

cursor-agent-sdk

Thin, typed Python bindings for the Cursor Cloud Agents API—drive cloud coding agents from CI, bots, or scripts instead of clicking through the dashboard. Built on httpx; sync by default, async when you already use asyncio.

Python 3.10+.


Install

Install from PyPI (recommended):

pip install cursor-agent-sdk

From source (contributors or a git checkout):

git clone <repository-url> && cd cursor-agent-api && pip install -e .

Auth

Keys live in the Cursor Dashboard → Cloud Agents. The API uses Basic auth: username = API key, password empty (curl -u 'KEY': …). Overview.


30-second run

import os
from cursor_agent import SyncClient

with SyncClient(os.environ["CURSOR_API_KEY"]) as client:
    agent = client.new_agent(repo="https://github.com/octocat/Hello-World", ref="main")
    print(agent.create("Add a one-line note to README.md."))

create starts the remote agent; follow_up("…") sends more prompts on the same run.


Model: client → agent → API

One client (connection + credentials). One agent handle per repo/PR you care about. Methods map 1:1 to https://api.cursor.com/v0.

flowchart TB
    subgraph sdk ["cursor-agent-sdk"]
        C["SyncClient / AsyncClient"]
        A["Agent / AsyncAgent"]
    end
    API[("Cursor Cloud Agents API\napi.cursor.com/v0")]
    C -->|new_agent| A
    A -->|create, follow_up, refresh| API
    C -->|me, list_agents, …| API

Opinions: Prefer Agent.create / follow_up over raw launch_agent / followup—they keep ids and sources straight. Use SyncClient unless your app is already async; then AsyncClient. This repo is not official Cursor software.


Example (sync)

import os
from cursor_agent import SyncClient

with SyncClient(os.environ["CURSOR_API_KEY"]) as client:
    agent = client.new_agent(repo="https://github.com/octocat/Hello-World", ref="main")
    out = agent.create(
        "Add CONTRIBUTING.md with PR guidelines.",
        target={"autoCreatePr": True},
    )
    print(out.get("id"), out.get("status"))
    agent.follow_up("Ask for a minimal repro in issues.")
    print(agent.refresh().get("status"))

Resume later: agent.attach("bc_…") then follow_up / refresh only.


Async

Same API; await client and AsyncAgent methods.

async def run():
    async with AsyncClient(os.environ["CURSOR_API_KEY"]) as client:
        a = client.new_agent(repo="https://github.com/octocat/Hello-World", ref="main")
        await a.create("Update README.")
        await a.follow_up("Keep it short.")

Lifecycle

Call Role
new_agent(repo=…, ref=…) or new_agent(pr_url=…) Bind GitHub source.
create(prompt, …) Once per handle — POST /v0/agents, stores id.
follow_up(prompt, …) Same cloud agent — POST /v0/agents/{id}/followup.

First create only: model, target, webhook, images. Follow-ups: prompt and images only.

PR instead of branch:

agent = client.new_agent(pr_url="https://github.com/octocat/Hello-World/pull/42")
agent.create("Small doc fixes only.")

HTTP surface

Client method Route
me GET /v0/me
list_models GET /v0/models
list_repositories GET /v0/repositories
list_agents GET /v0/agents
get_agent / get_conversation GET /v0/agents/{id}…
launch_agent POST /v0/agents
followup POST /v0/agents/{id}/followup
stop_agent / delete_agent POST / DELETE

Advanced

Custom httpxSyncClient.from_httpx_client(httpx.Client) / AsyncClient.from_httpx_client(httpx.AsyncClient) for proxies, retries, tracing, etc.

Errors — failed requests raise CursorAPIError with status_code and response.


Docs

Unofficial package; not maintained by Cursor.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cursor_agent_sdk-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cursor_agent_sdk-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file cursor_agent_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: cursor_agent_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for cursor_agent_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed4f640a8d318b8ee911cfb4866e8e438d6eb472284f45f3908c3a229c7cd0e6
MD5 ba0b62e4f65d97d83301bbad08174e82
BLAKE2b-256 58254faa2b9ef755a08e846ccb8c83e581472a00075334d566b705e7c4a0d9c1

See more details on using hashes here.

File details

Details for the file cursor_agent_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cursor_agent_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c0b2f8ff0b47ad768d624d76cd831388776efb7e94bbfbf26caa587e5523e6a
MD5 ee9c42e185e475468a4f0d1b1785b42b
BLAKE2b-256 d53b69fa0a9f19283d3b771c4b0270a1fdcb2ebe40571165e30a2f8b5fb95214

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page