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