Einen Message Batch erstellen
POST/v1/messages/batches
Sende einen Batch von Anfragen zur Erstellung von Nachrichten.
Die Message Batches API kann verwendet werden, um mehrere Messages-API-Anfragen auf einmal zu verarbeiten. Sobald ein Message Batch erstellt wurde, beginnt die Verarbeitung sofort. Die Fertigstellung von Batches kann bis zu 24 Stunden dauern.
Mehr über die Message Batches API erfährst du in unserem Benutzerhandbuch
Parameters
Returns
Einen Message Batch erstellen
using System;
using System.Collections.Generic;
using System.Text.Json;
using Messages = Anthropic.Models.Beta.Messages;
using Anthropic.Models.Beta.Messages.Batches;
using ModelsMessages = Anthropic.Models.Messages;
BatchCreateParams parameters = new()
{
Requests =
[
new()
{
CustomID = "my-custom-id-1",
Params = new()
{
MaxTokens = 1024,
Messages =
[
new Messages::BetaUserMessageParam("Hello, world")
],
Model = ModelsMessages::Model.ClaudeOpus5_5,
CacheControl = new() { Ttl = Messages::Ttl.Ttl5m },
Compaction = new() { Instructions = "instructions" },
Container = new Messages::BetaContainerParams()
{
ID = "id",
Skills =
[
new()
{
SkillID = "pdf",
Type = Messages::BetaSkillParamsType.Anthropic,
Version = "latest",
},
],
},
ContextManagement = new()
{
Edits =
[
new Messages::BetaClearToolUses20250919Edit()
{
ClearAtLeast = new(0),
ClearToolInputs = true,
ExcludeTools =
[
"string"
],
Keep = new(0),
Trigger = new Messages::BetaInputTokensTrigger(1),
},
],
},
Diagnostics = new()
{
PreviousMessageID = "previous_message_id"
},
FallbackCreditToken = "x",
Fallbacks = new Messages::Default(),
InferenceGeo = "inference_geo",
McpServers =
[
new()
{
Name = "name",
Url = "url",
AuthorizationToken = "authorization_token",
ToolConfiguration = new()
{
AllowedTools =
[
"string"
],
Enabled = true,
},
},
],
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") }
},
},
TaskBudget = new()
{
Total = 1024,
Remaining = 0,
},
},
OutputFormat = new()
{
Schema = new Dictionary<string, JsonElement>()
{
{ "foo", JsonSerializer.SerializeToElement("bar") }
},
},
ServiceTier = ServiceTier.Auto,
Speed = Speed.Standard,
StopSequences =
[
"string"
],
Stream = false,
System = new(
[
new Messages::BetaTextBlockParam()
{
Text = "Today's date is 2024-06-01.",
CacheControl = new() { Ttl = Messages::Ttl.Ttl5m },
Citations =
[
new Messages::BetaCitationCharLocationParam()
{
CitedText = "The grass is green. The sky is blue.",
DocumentIndex = 0,
DocumentTitle = "x",
EndCharIndex = 0,
StartCharIndex = 0,
},
],
},
]
),
Thinking = new Messages::BetaThinkingConfigAdaptive()
{
BlockBinding = new()
{
PrefixMismatchBehavior = Messages::BetaThinkingPrefixMismatchBehavior.Error,
},
Display = Messages::Display.Summarized,
},
Thread = new Messages::BetaThreadCreateParams(),
ToolChoice = new Messages::BetaToolChoiceAuto()
{
DisableParallelToolUse = true
},
Tools =
[
new Messages::BetaTool()
{
InputSchema = new()
{
Properties = new Dictionary<string, JsonElement>()
{
{ "location", JsonSerializer.SerializeToElement("bar") },
{ "unit", JsonSerializer.SerializeToElement("bar") },
},
Required =
[
"location"
],
},
Name = "name",
AllowedCallers =
[
Messages::BetaToolAllowedCaller.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::BetaToolType.Custom,
},
],
},
},
],
};
var betaMessageBatch = await client.Beta.Messages.Batches.Create(parameters);
Console.WriteLine(betaMessageBatch);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"
}