Skip to content

Commit 2bb29e7

Browse files
authored
feat(sdk): expose stable usage and managed control APIs (#10)
Add Forward credential rotation and hourly Usage aggregation, plus Managed Session cancellation and deployment-scoped Run queries. Include typed public exports, contract fixtures, live scenarios, generated API documentation, and changelog entries.
1 parent 2400e9f commit 2bb29e7

34 files changed

Lines changed: 2354 additions & 24 deletions

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ existing `0.1.0` release; earlier development prereleases are not listed.
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- Forward Vault Credential updates for secret rotation and metadata merge patches, with automatic retries disabled for write-only updates.
11+
- Forward Usage aggregation by Identity and Template using hourly `start_at` / `end_at` windows in Asia/Shanghai, with fractional `active_seconds` and multi-ID filters. Legacy timestamp parameters are not exposed.
12+
- Managed Session cancellation with the lightweight acknowledgement for both active and idle sessions, plus deployment-scoped Run listing and retrieval.
13+
814
## [0.2.0] - 2026-09-24
915

1016
### Added

‎CONTRIBUTING.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ The default test command excludes account-backed integration tests and must not
3434

3535
Never commit `.env.live`, tokens, credentials, generated logs, or test output. Integration scenarios must register cleanup immediately after creating a resource. Run them explicitly with `QODER_RUN_LIVE=1`; they are not part of public pull-request CI.
3636

37+
`tests/integration/test_api_expansion.py` adds Forward hourly Usage, Credential
38+
merge patches and secret redaction, and Managed Session cancellation before and
39+
after sending a turn. The existing Managed deployment scenario also checks
40+
scoped Run listing/retrieval. These are part of `test-live-all`; cancellation
41+
after sending a turn and deployment scenarios can execute models. Select a
42+
separate `QODER_LIVE_ENV_FILE` with matching URL and PAT for each CN/Global run.
43+
44+
Usage queries the last 24 completed whole hours in Asia/Shanghai in both regions;
45+
empty pages verify only the collection. A Session may finish before cancellation
46+
and return HTTP 200 instead of 202; tests record which response occurred. Those
47+
responses do not prove active cancellation occurred. Cleanup failures remain
48+
failures; offline replay exercises assertions and cleanup without account
49+
credentials.
50+
3751
The Forward and Managed integration files also include six `strict_response_contract` checks using a separate client with `_strict_response_validation=True`: model, template/agent, and session lists. They send only GET requests, inspect the first page with `limit=1` where supported, and allow empty lists. An empty list checks the response envelope; item schemas are checked when items exist. Returned items must have a non-empty string ID, and `data` must be present even when empty. Existing business scenarios continue to use the default lenient response parsing.
3852

3953
To run only these read-only checks:

‎README.md‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
The Qoder Cloud Agents Python SDK provides access to the Qoder Cloud Agents API from Python 3.10+. It ships synchronous and natively asynchronous clients, typed request parameters and response models, automatic pagination, SSE streaming, and file transfer.
88

9-
The API is exposed in two modes, and each has its own client, resources, and types. Forward is multi-tenant: sessions are created from an Identity and a Template, and it adds Schedule, Batch, and Channel. Managed is single-tenant: sessions are created from an Agent and an Environment, and it adds Deployment, Dream, and the Work API for self-hosted environments.
9+
The API is exposed in two modes, and each has its own client, resources, and types. Forward is multi-tenant: sessions are created from an Identity and a Template, and it adds Schedule, Batch, Channel, and Usage. Managed is single-tenant: sessions are created from an Agent and an Environment, and it adds Deployment, Dream, and the Work API for self-hosted environments.
1010

1111
## Installation
1212

@@ -104,6 +104,41 @@ asyncio.run(main())
104104

105105
Every method shown in this document has an async counterpart with the same name and signature. Async streams are opened with `async with await client.sessions.events.stream(...)`.
106106

107+
## Usage and cancellation
108+
109+
Forward Usage requires PAT or Admin SAT.
110+
111+
```python
112+
with Forward() as client:
113+
for row in client.usage.list_identities(
114+
start_at="2026-09-14T09:00:00", end_at="2026-09-14T12:00:00",
115+
identity_ids=["idn_one", "idn_two"],
116+
):
117+
print(row.identity_id, row.active_seconds, row.credits)
118+
119+
with Managed() as client:
120+
acknowledgement = client.sessions.cancel("sess_one")
121+
for run in client.deployments.runs.list("dep_one", limit=20):
122+
print(run.id)
123+
run = client.deployments.runs.retrieve("drun_one", deployment_id="dep_one")
124+
```
125+
126+
`usage.list_templates` accepts the same filters. Bounds are whole hours in
127+
Asia/Shanghai for CN and Global, with an inclusive start, exclusive end, and a
128+
maximum 744-hour span. Multi-ID filters accept lists or comma-separated strings.
129+
`active_seconds` preserves fractions. Legacy timestamp parameters and
130+
`duration_seconds` are not exposed.
131+
132+
`client.vaults.credentials.update("cred_one", vault_id="vault_one", auth={...})`
133+
rotates write-only secrets; only auth and metadata are patched, and omitted fields
134+
are preserved. `metadata=None` clears metadata; `metadata={"key": None}` deletes a
135+
key. This operation never retries automatically, even if client retries are enabled.
136+
137+
Session cancellation returns the lightweight `canceling` acknowledgement for
138+
active (HTTP 202) and idle (HTTP 200) sessions. The global `deployment_runs` resource
139+
remains available. All new methods also exist on `AsyncForward` / `AsyncManaged`;
140+
await requests or iterate pages with `async for`.
141+
107142
## Sessions
108143

109144
A session is the unit of agent execution. Forward materializes one from an Identity and a Template:

0 commit comments

Comments
 (0)