1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2
  3package anthropic
  4
  5import (
  6	"context"
  7	"encoding/json"
  8	"errors"
  9	"fmt"
 10	"net/http"
 11	"net/url"
 12	"time"
 13
 14	"github.com/anthropics/anthropic-sdk-go/internal/apijson"
 15	"github.com/anthropics/anthropic-sdk-go/internal/apiquery"
 16	"github.com/anthropics/anthropic-sdk-go/internal/requestconfig"
 17	"github.com/anthropics/anthropic-sdk-go/option"
 18	"github.com/anthropics/anthropic-sdk-go/packages/jsonl"
 19	"github.com/anthropics/anthropic-sdk-go/packages/pagination"
 20	"github.com/anthropics/anthropic-sdk-go/packages/param"
 21	"github.com/anthropics/anthropic-sdk-go/packages/respjson"
 22	"github.com/anthropics/anthropic-sdk-go/shared/constant"
 23)
 24
 25// BetaMessageBatchService contains methods and other services that help with
 26// interacting with the anthropic API.
 27//
 28// Note, unlike clients, this service does not read variables from the environment
 29// automatically. You should not instantiate this service directly, and instead use
 30// the [NewBetaMessageBatchService] method instead.
 31type BetaMessageBatchService struct {
 32	Options []option.RequestOption
 33}
 34
 35// NewBetaMessageBatchService generates a new service that applies the given
 36// options to each request. These options are applied after the parent client's
 37// options (if there is one), and before any request-specific options.
 38func NewBetaMessageBatchService(opts ...option.RequestOption) (r BetaMessageBatchService) {
 39	r = BetaMessageBatchService{}
 40	r.Options = opts
 41	return
 42}
 43
 44// Send a batch of Message creation requests.
 45//
 46// The Message Batches API can be used to process multiple Messages API requests at
 47// once. Once a Message Batch is created, it begins processing immediately. Batches
 48// can take up to 24 hours to complete.
 49//
 50// Learn more about the Message Batches API in our
 51// [user guide](/en/docs/build-with-claude/batch-processing)
 52func (r *BetaMessageBatchService) New(ctx context.Context, params BetaMessageBatchNewParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) {
 53	for _, v := range params.Betas {
 54		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
 55	}
 56	opts = append(r.Options[:], opts...)
 57	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...)
 58	path := "v1/messages/batches?beta=true"
 59	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
 60	return
 61}
 62
 63// This endpoint is idempotent and can be used to poll for Message Batch
 64// completion. To access the results of a Message Batch, make a request to the
 65// `results_url` field in the response.
 66//
 67// Learn more about the Message Batches API in our
 68// [user guide](/en/docs/build-with-claude/batch-processing)
 69func (r *BetaMessageBatchService) Get(ctx context.Context, messageBatchID string, query BetaMessageBatchGetParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) {
 70	for _, v := range query.Betas {
 71		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
 72	}
 73	opts = append(r.Options[:], opts...)
 74	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...)
 75	if messageBatchID == "" {
 76		err = errors.New("missing required message_batch_id parameter")
 77		return
 78	}
 79	path := fmt.Sprintf("v1/messages/batches/%s?beta=true", messageBatchID)
 80	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
 81	return
 82}
 83
 84// List all Message Batches within a Workspace. Most recently created batches are
 85// returned first.
 86//
 87// Learn more about the Message Batches API in our
 88// [user guide](/en/docs/build-with-claude/batch-processing)
 89func (r *BetaMessageBatchService) List(ctx context.Context, params BetaMessageBatchListParams, opts ...option.RequestOption) (res *pagination.Page[BetaMessageBatch], err error) {
 90	var raw *http.Response
 91	for _, v := range params.Betas {
 92		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
 93	}
 94	opts = append(r.Options[:], opts...)
 95	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24"), option.WithResponseInto(&raw)}, opts...)
 96	path := "v1/messages/batches?beta=true"
 97	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
 98	if err != nil {
 99		return nil, err
100	}
101	err = cfg.Execute()
102	if err != nil {
103		return nil, err
104	}
105	res.SetPageConfig(cfg, raw)
106	return res, nil
107}
108
109// List all Message Batches within a Workspace. Most recently created batches are
110// returned first.
111//
112// Learn more about the Message Batches API in our
113// [user guide](/en/docs/build-with-claude/batch-processing)
114func (r *BetaMessageBatchService) ListAutoPaging(ctx context.Context, params BetaMessageBatchListParams, opts ...option.RequestOption) *pagination.PageAutoPager[BetaMessageBatch] {
115	return pagination.NewPageAutoPager(r.List(ctx, params, opts...))
116}
117
118// Delete a Message Batch.
119//
120// Message Batches can only be deleted once they've finished processing. If you'd
121// like to delete an in-progress batch, you must first cancel it.
122//
123// Learn more about the Message Batches API in our
124// [user guide](/en/docs/build-with-claude/batch-processing)
125func (r *BetaMessageBatchService) Delete(ctx context.Context, messageBatchID string, body BetaMessageBatchDeleteParams, opts ...option.RequestOption) (res *BetaDeletedMessageBatch, err error) {
126	for _, v := range body.Betas {
127		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
128	}
129	opts = append(r.Options[:], opts...)
130	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...)
131	if messageBatchID == "" {
132		err = errors.New("missing required message_batch_id parameter")
133		return
134	}
135	path := fmt.Sprintf("v1/messages/batches/%s?beta=true", messageBatchID)
136	err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
137	return
138}
139
140// Batches may be canceled any time before processing ends. Once cancellation is
141// initiated, the batch enters a `canceling` state, at which time the system may
142// complete any in-progress, non-interruptible requests before finalizing
143// cancellation.
144//
145// The number of canceled requests is specified in `request_counts`. To determine
146// which requests were canceled, check the individual results within the batch.
147// Note that cancellation may not result in any canceled requests if they were
148// non-interruptible.
149//
150// Learn more about the Message Batches API in our
151// [user guide](/en/docs/build-with-claude/batch-processing)
152func (r *BetaMessageBatchService) Cancel(ctx context.Context, messageBatchID string, body BetaMessageBatchCancelParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) {
153	for _, v := range body.Betas {
154		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
155	}
156	opts = append(r.Options[:], opts...)
157	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...)
158	if messageBatchID == "" {
159		err = errors.New("missing required message_batch_id parameter")
160		return
161	}
162	path := fmt.Sprintf("v1/messages/batches/%s/cancel?beta=true", messageBatchID)
163	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
164	return
165}
166
167// Streams the results of a Message Batch as a `.jsonl` file.
168//
169// Each line in the file is a JSON object containing the result of a single request
170// in the Message Batch. Results are not guaranteed to be in the same order as
171// requests. Use the `custom_id` field to match results to requests.
172//
173// Learn more about the Message Batches API in our
174// [user guide](/en/docs/build-with-claude/batch-processing)
175func (r *BetaMessageBatchService) ResultsStreaming(ctx context.Context, messageBatchID string, query BetaMessageBatchResultsParams, opts ...option.RequestOption) (stream *jsonl.Stream[BetaMessageBatchIndividualResponse]) {
176	var (
177		raw *http.Response
178		err error
179	)
180	for _, v := range query.Betas {
181		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
182	}
183	opts = append(r.Options[:], opts...)
184	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24"), option.WithHeader("Accept", "application/x-jsonl")}, opts...)
185	if messageBatchID == "" {
186		err = errors.New("missing required message_batch_id parameter")
187		return
188	}
189	path := fmt.Sprintf("v1/messages/batches/%s/results?beta=true", messageBatchID)
190	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &raw, opts...)
191	return jsonl.NewStream[BetaMessageBatchIndividualResponse](raw, err)
192}
193
194type BetaDeletedMessageBatch struct {
195	// ID of the Message Batch.
196	ID string `json:"id,required"`
197	// Deleted object type.
198	//
199	// For Message Batches, this is always `"message_batch_deleted"`.
200	Type constant.MessageBatchDeleted `json:"type,required"`
201	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
202	JSON struct {
203		ID          respjson.Field
204		Type        respjson.Field
205		ExtraFields map[string]respjson.Field
206		raw         string
207	} `json:"-"`
208}
209
210// Returns the unmodified JSON received from the API
211func (r BetaDeletedMessageBatch) RawJSON() string { return r.JSON.raw }
212func (r *BetaDeletedMessageBatch) UnmarshalJSON(data []byte) error {
213	return apijson.UnmarshalRoot(data, r)
214}
215
216type BetaMessageBatch struct {
217	// Unique object identifier.
218	//
219	// The format and length of IDs may change over time.
220	ID string `json:"id,required"`
221	// RFC 3339 datetime string representing the time at which the Message Batch was
222	// archived and its results became unavailable.
223	ArchivedAt time.Time `json:"archived_at,required" format:"date-time"`
224	// RFC 3339 datetime string representing the time at which cancellation was
225	// initiated for the Message Batch. Specified only if cancellation was initiated.
226	CancelInitiatedAt time.Time `json:"cancel_initiated_at,required" format:"date-time"`
227	// RFC 3339 datetime string representing the time at which the Message Batch was
228	// created.
229	CreatedAt time.Time `json:"created_at,required" format:"date-time"`
230	// RFC 3339 datetime string representing the time at which processing for the
231	// Message Batch ended. Specified only once processing ends.
232	//
233	// Processing ends when every request in a Message Batch has either succeeded,
234	// errored, canceled, or expired.
235	EndedAt time.Time `json:"ended_at,required" format:"date-time"`
236	// RFC 3339 datetime string representing the time at which the Message Batch will
237	// expire and end processing, which is 24 hours after creation.
238	ExpiresAt time.Time `json:"expires_at,required" format:"date-time"`
239	// Processing status of the Message Batch.
240	//
241	// Any of "in_progress", "canceling", "ended".
242	ProcessingStatus BetaMessageBatchProcessingStatus `json:"processing_status,required"`
243	// Tallies requests within the Message Batch, categorized by their status.
244	//
245	// Requests start as `processing` and move to one of the other statuses only once
246	// processing of the entire batch ends. The sum of all values always matches the
247	// total number of requests in the batch.
248	RequestCounts BetaMessageBatchRequestCounts `json:"request_counts,required"`
249	// URL to a `.jsonl` file containing the results of the Message Batch requests.
250	// Specified only once processing ends.
251	//
252	// Results in the file are not guaranteed to be in the same order as requests. Use
253	// the `custom_id` field to match results to requests.
254	ResultsURL string `json:"results_url,required"`
255	// Object type.
256	//
257	// For Message Batches, this is always `"message_batch"`.
258	Type constant.MessageBatch `json:"type,required"`
259	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
260	JSON struct {
261		ID                respjson.Field
262		ArchivedAt        respjson.Field
263		CancelInitiatedAt respjson.Field
264		CreatedAt         respjson.Field
265		EndedAt           respjson.Field
266		ExpiresAt         respjson.Field
267		ProcessingStatus  respjson.Field
268		RequestCounts     respjson.Field
269		ResultsURL        respjson.Field
270		Type              respjson.Field
271		ExtraFields       map[string]respjson.Field
272		raw               string
273	} `json:"-"`
274}
275
276// Returns the unmodified JSON received from the API
277func (r BetaMessageBatch) RawJSON() string { return r.JSON.raw }
278func (r *BetaMessageBatch) UnmarshalJSON(data []byte) error {
279	return apijson.UnmarshalRoot(data, r)
280}
281
282// Processing status of the Message Batch.
283type BetaMessageBatchProcessingStatus string
284
285const (
286	BetaMessageBatchProcessingStatusInProgress BetaMessageBatchProcessingStatus = "in_progress"
287	BetaMessageBatchProcessingStatusCanceling  BetaMessageBatchProcessingStatus = "canceling"
288	BetaMessageBatchProcessingStatusEnded      BetaMessageBatchProcessingStatus = "ended"
289)
290
291type BetaMessageBatchCanceledResult struct {
292	Type constant.Canceled `json:"type,required"`
293	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
294	JSON struct {
295		Type        respjson.Field
296		ExtraFields map[string]respjson.Field
297		raw         string
298	} `json:"-"`
299}
300
301// Returns the unmodified JSON received from the API
302func (r BetaMessageBatchCanceledResult) RawJSON() string { return r.JSON.raw }
303func (r *BetaMessageBatchCanceledResult) UnmarshalJSON(data []byte) error {
304	return apijson.UnmarshalRoot(data, r)
305}
306
307type BetaMessageBatchErroredResult struct {
308	Error BetaErrorResponse `json:"error,required"`
309	Type  constant.Errored  `json:"type,required"`
310	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
311	JSON struct {
312		Error       respjson.Field
313		Type        respjson.Field
314		ExtraFields map[string]respjson.Field
315		raw         string
316	} `json:"-"`
317}
318
319// Returns the unmodified JSON received from the API
320func (r BetaMessageBatchErroredResult) RawJSON() string { return r.JSON.raw }
321func (r *BetaMessageBatchErroredResult) UnmarshalJSON(data []byte) error {
322	return apijson.UnmarshalRoot(data, r)
323}
324
325type BetaMessageBatchExpiredResult struct {
326	Type constant.Expired `json:"type,required"`
327	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
328	JSON struct {
329		Type        respjson.Field
330		ExtraFields map[string]respjson.Field
331		raw         string
332	} `json:"-"`
333}
334
335// Returns the unmodified JSON received from the API
336func (r BetaMessageBatchExpiredResult) RawJSON() string { return r.JSON.raw }
337func (r *BetaMessageBatchExpiredResult) UnmarshalJSON(data []byte) error {
338	return apijson.UnmarshalRoot(data, r)
339}
340
341// This is a single line in the response `.jsonl` file and does not represent the
342// response as a whole.
343type BetaMessageBatchIndividualResponse struct {
344	// Developer-provided ID created for each request in a Message Batch. Useful for
345	// matching results to requests, as results may be given out of request order.
346	//
347	// Must be unique for each request within the Message Batch.
348	CustomID string `json:"custom_id,required"`
349	// Processing result for this request.
350	//
351	// Contains a Message output if processing was successful, an error response if
352	// processing failed, or the reason why processing was not attempted, such as
353	// cancellation or expiration.
354	Result BetaMessageBatchResultUnion `json:"result,required"`
355	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
356	JSON struct {
357		CustomID    respjson.Field
358		Result      respjson.Field
359		ExtraFields map[string]respjson.Field
360		raw         string
361	} `json:"-"`
362}
363
364// Returns the unmodified JSON received from the API
365func (r BetaMessageBatchIndividualResponse) RawJSON() string { return r.JSON.raw }
366func (r *BetaMessageBatchIndividualResponse) UnmarshalJSON(data []byte) error {
367	return apijson.UnmarshalRoot(data, r)
368}
369
370type BetaMessageBatchRequestCounts struct {
371	// Number of requests in the Message Batch that have been canceled.
372	//
373	// This is zero until processing of the entire Message Batch has ended.
374	Canceled int64 `json:"canceled,required"`
375	// Number of requests in the Message Batch that encountered an error.
376	//
377	// This is zero until processing of the entire Message Batch has ended.
378	Errored int64 `json:"errored,required"`
379	// Number of requests in the Message Batch that have expired.
380	//
381	// This is zero until processing of the entire Message Batch has ended.
382	Expired int64 `json:"expired,required"`
383	// Number of requests in the Message Batch that are processing.
384	Processing int64 `json:"processing,required"`
385	// Number of requests in the Message Batch that have completed successfully.
386	//
387	// This is zero until processing of the entire Message Batch has ended.
388	Succeeded int64 `json:"succeeded,required"`
389	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
390	JSON struct {
391		Canceled    respjson.Field
392		Errored     respjson.Field
393		Expired     respjson.Field
394		Processing  respjson.Field
395		Succeeded   respjson.Field
396		ExtraFields map[string]respjson.Field
397		raw         string
398	} `json:"-"`
399}
400
401// Returns the unmodified JSON received from the API
402func (r BetaMessageBatchRequestCounts) RawJSON() string { return r.JSON.raw }
403func (r *BetaMessageBatchRequestCounts) UnmarshalJSON(data []byte) error {
404	return apijson.UnmarshalRoot(data, r)
405}
406
407// BetaMessageBatchResultUnion contains all possible properties and values from
408// [BetaMessageBatchSucceededResult], [BetaMessageBatchErroredResult],
409// [BetaMessageBatchCanceledResult], [BetaMessageBatchExpiredResult].
410//
411// Use the [BetaMessageBatchResultUnion.AsAny] method to switch on the variant.
412//
413// Use the methods beginning with 'As' to cast the union to one of its variants.
414type BetaMessageBatchResultUnion struct {
415	// This field is from variant [BetaMessageBatchSucceededResult].
416	Message BetaMessage `json:"message"`
417	// Any of "succeeded", "errored", "canceled", "expired".
418	Type string `json:"type"`
419	// This field is from variant [BetaMessageBatchErroredResult].
420	Error BetaErrorResponse `json:"error"`
421	JSON  struct {
422		Message respjson.Field
423		Type    respjson.Field
424		Error   respjson.Field
425		raw     string
426	} `json:"-"`
427}
428
429// anyBetaMessageBatchResult is implemented by each variant of
430// [BetaMessageBatchResultUnion] to add type safety for the return type of
431// [BetaMessageBatchResultUnion.AsAny]
432type anyBetaMessageBatchResult interface {
433	implBetaMessageBatchResultUnion()
434}
435
436func (BetaMessageBatchSucceededResult) implBetaMessageBatchResultUnion() {}
437func (BetaMessageBatchErroredResult) implBetaMessageBatchResultUnion()   {}
438func (BetaMessageBatchCanceledResult) implBetaMessageBatchResultUnion()  {}
439func (BetaMessageBatchExpiredResult) implBetaMessageBatchResultUnion()   {}
440
441// Use the following switch statement to find the correct variant
442//
443//	switch variant := BetaMessageBatchResultUnion.AsAny().(type) {
444//	case anthropic.BetaMessageBatchSucceededResult:
445//	case anthropic.BetaMessageBatchErroredResult:
446//	case anthropic.BetaMessageBatchCanceledResult:
447//	case anthropic.BetaMessageBatchExpiredResult:
448//	default:
449//	  fmt.Errorf("no variant present")
450//	}
451func (u BetaMessageBatchResultUnion) AsAny() anyBetaMessageBatchResult {
452	switch u.Type {
453	case "succeeded":
454		return u.AsSucceeded()
455	case "errored":
456		return u.AsErrored()
457	case "canceled":
458		return u.AsCanceled()
459	case "expired":
460		return u.AsExpired()
461	}
462	return nil
463}
464
465func (u BetaMessageBatchResultUnion) AsSucceeded() (v BetaMessageBatchSucceededResult) {
466	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
467	return
468}
469
470func (u BetaMessageBatchResultUnion) AsErrored() (v BetaMessageBatchErroredResult) {
471	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
472	return
473}
474
475func (u BetaMessageBatchResultUnion) AsCanceled() (v BetaMessageBatchCanceledResult) {
476	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
477	return
478}
479
480func (u BetaMessageBatchResultUnion) AsExpired() (v BetaMessageBatchExpiredResult) {
481	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
482	return
483}
484
485// Returns the unmodified JSON received from the API
486func (u BetaMessageBatchResultUnion) RawJSON() string { return u.JSON.raw }
487
488func (r *BetaMessageBatchResultUnion) UnmarshalJSON(data []byte) error {
489	return apijson.UnmarshalRoot(data, r)
490}
491
492type BetaMessageBatchSucceededResult struct {
493	Message BetaMessage        `json:"message,required"`
494	Type    constant.Succeeded `json:"type,required"`
495	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
496	JSON struct {
497		Message     respjson.Field
498		Type        respjson.Field
499		ExtraFields map[string]respjson.Field
500		raw         string
501	} `json:"-"`
502}
503
504// Returns the unmodified JSON received from the API
505func (r BetaMessageBatchSucceededResult) RawJSON() string { return r.JSON.raw }
506func (r *BetaMessageBatchSucceededResult) UnmarshalJSON(data []byte) error {
507	return apijson.UnmarshalRoot(data, r)
508}
509
510type BetaMessageBatchNewParams struct {
511	// List of requests for prompt completion. Each is an individual request to create
512	// a Message.
513	Requests []BetaMessageBatchNewParamsRequest `json:"requests,omitzero,required"`
514	// Optional header to specify the beta version(s) you want to use.
515	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
516	paramObj
517}
518
519func (r BetaMessageBatchNewParams) MarshalJSON() (data []byte, err error) {
520	type shadow BetaMessageBatchNewParams
521	return param.MarshalObject(r, (*shadow)(&r))
522}
523func (r *BetaMessageBatchNewParams) UnmarshalJSON(data []byte) error {
524	return apijson.UnmarshalRoot(data, r)
525}
526
527// The properties CustomID, Params are required.
528type BetaMessageBatchNewParamsRequest struct {
529	// Developer-provided ID created for each request in a Message Batch. Useful for
530	// matching results to requests, as results may be given out of request order.
531	//
532	// Must be unique for each request within the Message Batch.
533	CustomID string `json:"custom_id,required"`
534	// Messages API creation parameters for the individual request.
535	//
536	// See the [Messages API reference](/en/api/messages) for full documentation on
537	// available parameters.
538	Params BetaMessageBatchNewParamsRequestParams `json:"params,omitzero,required"`
539	paramObj
540}
541
542func (r BetaMessageBatchNewParamsRequest) MarshalJSON() (data []byte, err error) {
543	type shadow BetaMessageBatchNewParamsRequest
544	return param.MarshalObject(r, (*shadow)(&r))
545}
546func (r *BetaMessageBatchNewParamsRequest) UnmarshalJSON(data []byte) error {
547	return apijson.UnmarshalRoot(data, r)
548}
549
550// Messages API creation parameters for the individual request.
551//
552// See the [Messages API reference](/en/api/messages) for full documentation on
553// available parameters.
554//
555// The properties MaxTokens, Messages, Model are required.
556type BetaMessageBatchNewParamsRequestParams struct {
557	// The maximum number of tokens to generate before stopping.
558	//
559	// Note that our models may stop _before_ reaching this maximum. This parameter
560	// only specifies the absolute maximum number of tokens to generate.
561	//
562	// Different models have different maximum values for this parameter. See
563	// [models](https://docs.anthropic.com/en/docs/models-overview) for details.
564	MaxTokens int64 `json:"max_tokens,required"`
565	// Input messages.
566	//
567	// Our models are trained to operate on alternating `user` and `assistant`
568	// conversational turns. When creating a new `Message`, you specify the prior
569	// conversational turns with the `messages` parameter, and the model then generates
570	// the next `Message` in the conversation. Consecutive `user` or `assistant` turns
571	// in your request will be combined into a single turn.
572	//
573	// Each input message must be an object with a `role` and `content`. You can
574	// specify a single `user`-role message, or you can include multiple `user` and
575	// `assistant` messages.
576	//
577	// If the final message uses the `assistant` role, the response content will
578	// continue immediately from the content in that message. This can be used to
579	// constrain part of the model's response.
580	//
581	// Example with a single `user` message:
582	//
583	// ```json
584	// [{ "role": "user", "content": "Hello, Claude" }]
585	// ```
586	//
587	// Example with multiple conversational turns:
588	//
589	// ```json
590	// [
591	//
592	//	{ "role": "user", "content": "Hello there." },
593	//	{ "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
594	//	{ "role": "user", "content": "Can you explain LLMs in plain English?" }
595	//
596	// ]
597	// ```
598	//
599	// Example with a partially-filled response from Claude:
600	//
601	// ```json
602	// [
603	//
604	//	{
605	//	  "role": "user",
606	//	  "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
607	//	},
608	//	{ "role": "assistant", "content": "The best answer is (" }
609	//
610	// ]
611	// ```
612	//
613	// Each input message `content` may be either a single `string` or an array of
614	// content blocks, where each block has a specific `type`. Using a `string` for
615	// `content` is shorthand for an array of one content block of type `"text"`. The
616	// following input messages are equivalent:
617	//
618	// ```json
619	// { "role": "user", "content": "Hello, Claude" }
620	// ```
621	//
622	// ```json
623	// { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
624	// ```
625	//
626	// Starting with Claude 3 models, you can also send image content blocks:
627	//
628	// ```json
629	//
630	//	{
631	//	  "role": "user",
632	//	  "content": [
633	//	    {
634	//	      "type": "image",
635	//	      "source": {
636	//	        "type": "base64",
637	//	        "media_type": "image/jpeg",
638	//	        "data": "/9j/4AAQSkZJRg..."
639	//	      }
640	//	    },
641	//	    { "type": "text", "text": "What is in this image?" }
642	//	  ]
643	//	}
644	//
645	// ```
646	//
647	// We currently support the `base64` source type for images, and the `image/jpeg`,
648	// `image/png`, `image/gif`, and `image/webp` media types.
649	//
650	// See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
651	// more input examples.
652	//
653	// Note that if you want to include a
654	// [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
655	// the top-level `system` parameter — there is no `"system"` role for input
656	// messages in the Messages API.
657	//
658	// There is a limit of 100000 messages in a single request.
659	Messages []BetaMessageParam `json:"messages,omitzero,required"`
660	// The model that will complete your prompt.\n\nSee
661	// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
662	// details and options.
663	Model Model `json:"model,omitzero,required"`
664	// Container identifier for reuse across requests.
665	Container param.Opt[string] `json:"container,omitzero"`
666	// Whether to incrementally stream the response using server-sent events.
667	//
668	// See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
669	// details.
670	Stream param.Opt[bool] `json:"stream,omitzero"`
671	// Amount of randomness injected into the response.
672	//
673	// Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
674	// for analytical / multiple choice, and closer to `1.0` for creative and
675	// generative tasks.
676	//
677	// Note that even with `temperature` of `0.0`, the results will not be fully
678	// deterministic.
679	Temperature param.Opt[float64] `json:"temperature,omitzero"`
680	// Only sample from the top K options for each subsequent token.
681	//
682	// Used to remove "long tail" low probability responses.
683	// [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
684	//
685	// Recommended for advanced use cases only. You usually only need to use
686	// `temperature`.
687	TopK param.Opt[int64] `json:"top_k,omitzero"`
688	// Use nucleus sampling.
689	//
690	// In nucleus sampling, we compute the cumulative distribution over all the options
691	// for each subsequent token in decreasing probability order and cut it off once it
692	// reaches a particular probability specified by `top_p`. You should either alter
693	// `temperature` or `top_p`, but not both.
694	//
695	// Recommended for advanced use cases only. You usually only need to use
696	// `temperature`.
697	TopP param.Opt[float64] `json:"top_p,omitzero"`
698	// MCP servers to be utilized in this request
699	MCPServers []BetaRequestMCPServerURLDefinitionParam `json:"mcp_servers,omitzero"`
700	// An object describing metadata about the request.
701	Metadata BetaMetadataParam `json:"metadata,omitzero"`
702	// Determines whether to use priority capacity (if available) or standard capacity
703	// for this request.
704	//
705	// Anthropic offers different levels of service for your API requests. See
706	// [service-tiers](https://docs.anthropic.com/en/api/service-tiers) for details.
707	//
708	// Any of "auto", "standard_only".
709	ServiceTier string `json:"service_tier,omitzero"`
710	// Custom text sequences that will cause the model to stop generating.
711	//
712	// Our models will normally stop when they have naturally completed their turn,
713	// which will result in a response `stop_reason` of `"end_turn"`.
714	//
715	// If you want the model to stop generating when it encounters custom strings of
716	// text, you can use the `stop_sequences` parameter. If the model encounters one of
717	// the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
718	// and the response `stop_sequence` value will contain the matched stop sequence.
719	StopSequences []string `json:"stop_sequences,omitzero"`
720	// System prompt.
721	//
722	// A system prompt is a way of providing context and instructions to Claude, such
723	// as specifying a particular goal or role. See our
724	// [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
725	System []BetaTextBlockParam `json:"system,omitzero"`
726	// Configuration for enabling Claude's extended thinking.
727	//
728	// When enabled, responses include `thinking` content blocks showing Claude's
729	// thinking process before the final answer. Requires a minimum budget of 1,024
730	// tokens and counts towards your `max_tokens` limit.
731	//
732	// See
733	// [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
734	// for details.
735	Thinking BetaThinkingConfigParamUnion `json:"thinking,omitzero"`
736	// How the model should use the provided tools. The model can use a specific tool,
737	// any available tool, decide by itself, or not use tools at all.
738	ToolChoice BetaToolChoiceUnionParam `json:"tool_choice,omitzero"`
739	// Definitions of tools that the model may use.
740	//
741	// If you include `tools` in your API request, the model may return `tool_use`
742	// content blocks that represent the model's use of those tools. You can then run
743	// those tools using the tool input generated by the model and then optionally
744	// return results back to the model using `tool_result` content blocks.
745	//
746	// Each tool definition includes:
747	//
748	//   - `name`: Name of the tool.
749	//   - `description`: Optional, but strongly-recommended description of the tool.
750	//   - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
751	//     tool `input` shape that the model will produce in `tool_use` output content
752	//     blocks.
753	//
754	// For example, if you defined `tools` as:
755	//
756	// ```json
757	// [
758	//
759	//	{
760	//	  "name": "get_stock_price",
761	//	  "description": "Get the current stock price for a given ticker symbol.",
762	//	  "input_schema": {
763	//	    "type": "object",
764	//	    "properties": {
765	//	      "ticker": {
766	//	        "type": "string",
767	//	        "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
768	//	      }
769	//	    },
770	//	    "required": ["ticker"]
771	//	  }
772	//	}
773	//
774	// ]
775	// ```
776	//
777	// And then asked the model "What's the S&P 500 at today?", the model might produce
778	// `tool_use` content blocks in the response like this:
779	//
780	// ```json
781	// [
782	//
783	//	{
784	//	  "type": "tool_use",
785	//	  "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
786	//	  "name": "get_stock_price",
787	//	  "input": { "ticker": "^GSPC" }
788	//	}
789	//
790	// ]
791	// ```
792	//
793	// You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
794	// input, and return the following back to the model in a subsequent `user`
795	// message:
796	//
797	// ```json
798	// [
799	//
800	//	{
801	//	  "type": "tool_result",
802	//	  "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
803	//	  "content": "259.75 USD"
804	//	}
805	//
806	// ]
807	// ```
808	//
809	// Tools can be used for workflows that include running client-side tools and
810	// functions, or more generally whenever you want the model to produce a particular
811	// JSON structure of output.
812	//
813	// See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
814	Tools []BetaToolUnionParam `json:"tools,omitzero"`
815	paramObj
816}
817
818func (r BetaMessageBatchNewParamsRequestParams) MarshalJSON() (data []byte, err error) {
819	type shadow BetaMessageBatchNewParamsRequestParams
820	return param.MarshalObject(r, (*shadow)(&r))
821}
822func (r *BetaMessageBatchNewParamsRequestParams) UnmarshalJSON(data []byte) error {
823	return apijson.UnmarshalRoot(data, r)
824}
825
826func init() {
827	apijson.RegisterFieldValidator[BetaMessageBatchNewParamsRequestParams](
828		"service_tier", "auto", "standard_only",
829	)
830}
831
832type BetaMessageBatchGetParams struct {
833	// Optional header to specify the beta version(s) you want to use.
834	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
835	paramObj
836}
837
838type BetaMessageBatchListParams struct {
839	// ID of the object to use as a cursor for pagination. When provided, returns the
840	// page of results immediately after this object.
841	AfterID param.Opt[string] `query:"after_id,omitzero" json:"-"`
842	// ID of the object to use as a cursor for pagination. When provided, returns the
843	// page of results immediately before this object.
844	BeforeID param.Opt[string] `query:"before_id,omitzero" json:"-"`
845	// Number of items to return per page.
846	//
847	// Defaults to `20`. Ranges from `1` to `1000`.
848	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
849	// Optional header to specify the beta version(s) you want to use.
850	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
851	paramObj
852}
853
854// URLQuery serializes [BetaMessageBatchListParams]'s query parameters as
855// `url.Values`.
856func (r BetaMessageBatchListParams) URLQuery() (v url.Values, err error) {
857	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
858		ArrayFormat:  apiquery.ArrayQueryFormatComma,
859		NestedFormat: apiquery.NestedQueryFormatBrackets,
860	})
861}
862
863type BetaMessageBatchDeleteParams struct {
864	// Optional header to specify the beta version(s) you want to use.
865	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
866	paramObj
867}
868
869type BetaMessageBatchCancelParams struct {
870	// Optional header to specify the beta version(s) you want to use.
871	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
872	paramObj
873}
874
875type BetaMessageBatchResultsParams struct {
876	// Optional header to specify the beta version(s) you want to use.
877	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
878	paramObj
879}