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
The Message Batches API is a powerful, cost-effective way to asynchronously process large volumes of [Messages](https://docs.anthropic.com/en/api/messages) requests. This approach is well-suited to tasks that do not require immediate responses, reducing costs by 50% while increasing throughput.
91
+
92
+
This is especially useful for bulk operations that don’t require immediate results.
93
+
94
+
Here's an example of how to process many messages with the Message Batches API:
95
+
96
+
```swift
97
+
let anthropic =Anthropic(apiKey: "YOUR_OWN_API_KEY")
98
+
99
+
let messages = [
100
+
Message(role: .user, content: [.text("Write a haiku about robots.")]),
101
+
Message(role: .user, content: [.text("Write a haiku about robots. Skip the preamble; go straight into the poem.")]),
102
+
Message(role: .user, content: [.text("Who is the best basketball player of all time?")]),
103
+
Message(role: .user, content: [.text("Who is the best basketball player of all time? Yes, there are differing opinions, but if you absolutely had to pick one player, who would it be?")])
104
+
// ....
105
+
]
106
+
107
+
let batch =MessageBatch(
108
+
customId: "my-first-batch-request",
109
+
parameter: .init(
110
+
messages: messages,
111
+
maxTokens: 1024
112
+
)
113
+
)
114
+
115
+
let response =tryawait anthropic.messageBatches.createBatches(batches: [batch])
Token counting enables you to determine the number of tokens in a message before sending it to Claude, helping you make informed decisions about your prompts and usage. With token counting, you can
196
+
197
+
- Proactively manage rate limits and costs
198
+
- Make smart model routing decisions
199
+
- Optimize prompts to be a specific length
200
+
201
+
```swift
202
+
let anthropic =Anthropic(apiKey: "YOUR_OWN_API_KEY")
203
+
204
+
let message =Message(role: .user, content: [.text("Find flights from San Francisco to a place with warmer weather.")])
205
+
let response =tryawait anthropic.countTokens.countTokens(
The token counting endpoint accepts the same structured list of inputs for creating a message, including support for system prompts, tools, images, and PDFs. The response contains the total number of input tokens.
Claude is capable of interacting with external client-side tools and functions, allowing you to equip Claude with your own custom tools to perform a wider variety of tasks.
@@ -134,36 +265,6 @@ let response = try await anthropic.messages.createMessage(
The Message Batches API is a powerful, cost-effective way to asynchronously process large volumes of [Messages](https://docs.anthropic.com/en/api/messages) requests. This approach is well-suited to tasks that do not require immediate responses, reducing costs by 50% while increasing throughput.
140
-
141
-
This is especially useful for bulk operations that don’t require immediate results.
142
-
143
-
Here's an example of how to process many messages with the Message Bathches API:
144
-
145
-
```swift
146
-
let anthropic =Anthropic(apiKey: "YOUR_OWN_API_KEY")
147
-
148
-
let messages = [
149
-
Message(role: .user, content: [.text("Write a haiku about robots.")]),
150
-
Message(role: .user, content: [.text("Write a haiku about robots. Skip the preamble; go straight into the poem.")]),
151
-
Message(role: .user, content: [.text("Who is the best basketball player of all time?")]),
152
-
Message(role: .user, content: [.text("Who is the best basketball player of all time? Yes, there are differing opinions, but if you absolutely had to pick one player, who would it be?")])
153
-
// ....
154
-
]
155
-
156
-
let batch =MessageBatch(
157
-
customId: "my-first-batch-request",
158
-
parameter: .init(
159
-
messages: messages,
160
-
maxTokens: 1024
161
-
)
162
-
)
163
-
164
-
let response =tryawait anthropic.messageBatches.createBatches(batches: [batch])
165
-
```
166
-
167
268
### [Computer Use (beta)](https://docs.anthropic.com/en/docs/build-with-claude/computer-use#computer-tool)
168
269
169
270
The upgraded Claude 3.5 Sonnet model is capable of interacting with tools that can manipulate a computer desktop environment.
@@ -184,30 +285,6 @@ let response = try await anthropic.messages.createMessage(
Token counting enables you to determine the number of tokens in a message before sending it to Claude, helping you make informed decisions about your prompts and usage. With token counting, you can
190
-
191
-
- Proactively manage rate limits and costs
192
-
- Make smart model routing decisions
193
-
- Optimize prompts to be a specific length
194
-
195
-
```swift
196
-
let anthropic =Anthropic(apiKey: "YOUR_OWN_API_KEY")
197
-
198
-
let message =Message(role: .user, content: [.text("Find flights from San Francisco to a place with warmer weather.")])
199
-
let response =tryawait anthropic.countTokens.countTokens(
The token counting endpoint accepts the same structured list of inputs for creating a message, including support for system prompts, tools, images, and PDFs. The response contains the total number of input tokens.
210
-
211
288
## Extensions
212
289
213
290
By introducing an extension Swift package, it is possible to access the Anthropic Claude API through AWS Bedrock and Vertex AI. The supported services are as follows:
0 commit comments