创建消息批次
POST/v1/messages/batches
发送一批消息创建请求。
Message Batches API 可用于一次处理多个 Messages API 请求。消息批次一经创建,便会立即开始处理。批次最多可能需要 24 小时才能完成。
在我们的用户指南中了解有关 Message Batches API 的更多信息
Parameters
Returns
创建消息批次
using System;
using System.Collections.Generic;
using System.Text.Json;
using Messages = Anthropic.Models.Messages;
using Anthropic.Models.Messages.Batches;
BatchCreateParams parameters = new()
{
Requests =
[
new()
{
CustomID = "my-custom-id-1",
Params = new()
{
MaxTokens = 1024,
Messages =
[
new Messages::UserMessageParam("Hello, world")
],
Model = Messages::Model.ClaudeOpus5_5,
CacheControl = new() { Ttl = Messages::Ttl.Ttl5m },
Container = new Messages::ContainerParams()
{
ID = "id",
Skills =
[
new()
{
SkillID = "pdf",
Type = Messages::SkillParamsType.Anthropic,
Version = "latest",
},
],
},
Diagnostics = new()
{
PreviousMessageID = "previous_message_id"
},
InferenceGeo = "inference_geo",
Metadata = new()
{
UserID = "13803d75-b4b5-4c3e-b2a2-6f21399b021b"
},
OutputConfig = new()
{
Effort = Messages::Effort.Low,
Format = new()
{
Schema = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
},
},
ServiceTier = ServiceTier.Auto,
Speed = Speed.Standard,
StopSequences =
[
"string"
],
Stream = false,
System = new(
[
new Messages::TextBlockParam()
{
Text = "Today's date is 2024-06-01.",
CacheControl = new() { Ttl = Messages::Ttl.Ttl5m },
Citations =
[
new Messages::CitationCharLocationParam()
{
CitedText = "The grass is green. The sky is blue.",
DocumentIndex = 0,
DocumentTitle = "x",
EndCharIndex = 0,
StartCharIndex = 0,
},
],
},
]
),
Thinking = new Messages::ThinkingConfigAdaptive()
{
Display = Messages::Display.Summarized
},
ToolChoice = new Messages::ToolChoiceAuto()
{
DisableParallelToolUse = true
},
Tools =
[
new Messages::Tool()
{
InputSchema = new()
{
Properties = new Dictionary<string, JsonElement>()
{
{ "location", JsonSerializer.SerializeToElement("bar") },
{ "unit", JsonSerializer.SerializeToElement("bar") },
},
Required =
[
"location"
],
},
Name = "name",
AllowedCallers =
[
Messages::ToolAllowedCaller.Direct
],
CacheControl = new() { Ttl = Messages::Ttl.Ttl5m },
DeferLoading = true,
Description = "Get the current weather in a given location",
EagerInputStreaming = true,
InputExamples =
[
new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") },
},
],
Strict = true,
Type = Messages::Type.Custom,
},
],
},
},
],
};
var messageBatch = await client.Messages.Batches.Create(parameters);
Console.WriteLine(messageBatch);Response 200
{
"id": "msgbatch_013Zva2CMHLNnXjNJJKqJ2EF",
"archived_at": "2024-08-20T18:37:24.100435Z",
"cancel_initiated_at": "2024-08-20T18:37:24.100435Z",
"created_at": "2024-08-20T18:37:24.100435Z",
"ended_at": "2024-08-20T18:37:24.100435Z",
"expires_at": "2024-08-20T18:37:24.100435Z",
"processing_status": "in_progress",
"request_counts": {
"canceled": 10,
"errored": 30,
"expired": 10,
"processing": 100,
"succeeded": 50
},
"results_url": "https://api.anthropic.com/v1/messages/batches/msgbatch_013Zva2CMHLNnXjNJJKqJ2EF/results",
"type": "message_batch"
}Returns Examples
Response 200
{
"id": "msgbatch_013Zva2CMHLNnXjNJJKqJ2EF",
"archived_at": "2024-08-20T18:37:24.100435Z",
"cancel_initiated_at": "2024-08-20T18:37:24.100435Z",
"created_at": "2024-08-20T18:37:24.100435Z",
"ended_at": "2024-08-20T18:37:24.100435Z",
"expires_at": "2024-08-20T18:37:24.100435Z",
"processing_status": "in_progress",
"request_counts": {
"canceled": 10,
"errored": 30,
"expired": 10,
"processing": 100,
"succeeded": 50
},
"results_url": "https://api.anthropic.com/v1/messages/batches/msgbatch_013Zva2CMHLNnXjNJJKqJ2EF/results",
"type": "message_batch"
}