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
+115
Original file line number
Diff line number
Diff line change
@@ -173,6 +173,50 @@ message.usage
173
173
# Usage(input_tokens=25, output_tokens=13)
174
174
```
175
175
176
+
## Message Batches
177
+
178
+
This SDK provides beta support for the [Message Batches API](https://docs.anthropic.com/en/docs/build-with-claude/message-batches) under the `client.beta.messages.batches` namespace.
179
+
180
+
181
+
### Creating a batch
182
+
183
+
Message Batches take the exact same request params as the standard Messages API:
This SDK provides support for tool use, aka function calling. More details can be found in [the documentation](https://docs.anthropic.com/claude/docs/tool-use).
@@ -250,6 +294,77 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
250
294
251
295
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
252
296
297
+
## Pagination
298
+
299
+
List methods in the Anthropic API are paginated.
300
+
301
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
302
+
303
+
```python
304
+
from anthropic import Anthropic
305
+
306
+
client = Anthropic()
307
+
308
+
all_batches = []
309
+
# Automatically fetches more pages as needed.
310
+
for batch in client.beta.messages.batches.list(
311
+
limit=20,
312
+
):
313
+
# Do something with batch here
314
+
all_batches.append(batch)
315
+
print(all_batches)
316
+
```
317
+
318
+
Or, asynchronously:
319
+
320
+
```python
321
+
import asyncio
322
+
from anthropic import AsyncAnthropic
323
+
324
+
client = AsyncAnthropic()
325
+
326
+
327
+
asyncdefmain() -> None:
328
+
all_batches = []
329
+
# Iterate through items across all pages, issuing requests as needed.
330
+
asyncfor batch in client.beta.messages.batches.list(
331
+
limit=20,
332
+
):
333
+
all_batches.append(batch)
334
+
print(all_batches)
335
+
336
+
337
+
asyncio.run(main())
338
+
```
339
+
340
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `anthropic.APIConnectionError` is raised.
0 commit comments