You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-36Lines changed: 10 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ from opencode_ai import Opencode
29
29
30
30
client = Opencode()
31
31
32
-
events= client.event.list()
32
+
sessions= client.session.list()
33
33
```
34
34
35
35
## Async usage
@@ -44,7 +44,7 @@ client = AsyncOpencode()
44
44
45
45
46
46
asyncdefmain() -> None:
47
-
events=await client.event.list()
47
+
sessions=await client.session.list()
48
48
49
49
50
50
asyncio.run(main())
@@ -75,38 +75,12 @@ async def main() -> None:
75
75
asyncwith AsyncOpencode(
76
76
http_client=DefaultAioHttpClient(),
77
77
) as client:
78
-
events=await client.event.list()
78
+
sessions=await client.session.list()
79
79
80
80
81
81
asyncio.run(main())
82
82
```
83
83
84
-
## Streaming responses
85
-
86
-
We provide support for streaming responses using Server Side Events (SSE).
87
-
88
-
```python
89
-
from opencode_ai import Opencode
90
-
91
-
client = Opencode()
92
-
93
-
stream = client.event.list()
94
-
for events in stream:
95
-
print(events)
96
-
```
97
-
98
-
The async client uses the exact same interface.
99
-
100
-
```python
101
-
from opencode_ai import AsyncOpencode
102
-
103
-
client = AsyncOpencode()
104
-
105
-
stream =await client.event.list()
106
-
asyncfor events in stream:
107
-
print(events)
108
-
```
109
-
110
84
## Using types
111
85
112
86
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
@@ -132,7 +106,7 @@ from opencode_ai import Opencode
132
106
client = Opencode()
133
107
134
108
try:
135
-
client.event.list()
109
+
client.session.list()
136
110
except opencode_ai.APIConnectionError as e:
137
111
print("The server could not be reached")
138
112
print(e.__cause__) # an underlying Exception, likely raised within httpx.
@@ -175,7 +149,7 @@ client = Opencode(
175
149
)
176
150
177
151
# Or, configure per-request:
178
-
client.with_options(max_retries=5).event.list()
152
+
client.with_options(max_retries=5).session.list()
179
153
```
180
154
181
155
### Timeouts
@@ -198,7 +172,7 @@ client = Opencode(
198
172
)
199
173
200
174
# Override per-request:
201
-
client.with_options(timeout=5.0).event.list()
175
+
client.with_options(timeout=5.0).session.list()
202
176
```
203
177
204
178
On timeout, an `APITimeoutError` is thrown.
@@ -239,11 +213,11 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
event= response.parse() # get the object that `event.list()` would have returned
246
-
print(event)
219
+
session= response.parse() # get the object that `session.list()` would have returned
220
+
print(session)
247
221
```
248
222
249
223
These methods return an [`APIResponse`](https://github.com/sst/opencode-sdk-python/tree/main/src/opencode_ai/_response.py) object.
@@ -257,7 +231,7 @@ The above interface eagerly reads the full response body when you make the reque
257
231
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
258
232
259
233
```python
260
-
with client.event.with_streaming_response.list() as response:
234
+
with client.session.with_streaming_response.list() as response:
0 commit comments