Batches

View as Markdown

Batches

Process thousands of requests asynchronously. Results are returned inline in the poll response — no separate file download required.

1. Create a Batch

1batch, err := client.Batches.Create(ctx, meshapi.CreateBatchParams{
2 Requests: []meshapi.BatchRequestItem{
3 {
4 CustomID: "req-1",
5 Body: map[string]interface{}{
6 "model": "openai/gpt-5.4",
7 "messages": []map[string]string{
8 {"role": "user", "content": "Say hi."},
9 },
10 },
11 },
12 },
13 CompletionWindow: "24h",
14})

2. Monitor and Retrieve

1// Poll until completed
2status, _ := client.Batches.Get(ctx, batch.ID)
3
4// Results are included inline once status is "completed"
5if status.Status == "completed" {
6 for _, result := range status.Results {
7 fmt.Println(result.CustomID, result.Response.Body.Choices[0].Message.Content)
8 }
9}