From b3a63e7cbf73d06141750cf126af25412b12061d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:07:00 +0000 Subject: [PATCH 1/7] feat(api): add message batch delete endpoint (#81) --- .stats.yml | 4 +-- api.md | 4 +++ betamessagebatch.go | 64 ++++++++++++++++++++++++++++++++++++++++ betamessagebatch_test.go | 28 ++++++++++++++++++ messagebatch.go | 58 ++++++++++++++++++++++++++++++++++++ messagebatch_test.go | 22 ++++++++++++++ 6 files changed, 178 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 14c789b..239e17b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 19 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-9563716c7b08b8936ba450ad05005d12cf5ca3b9a37fab8126ed372e422d6de6.yml +configured_endpoints: 21 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-fd67aea6883f1ee9e46f31a42d3940f0acb1749e787055bd9b9f278b20fa53ec.yml diff --git a/api.md b/api.md index c4f13c0..f710db4 100644 --- a/api.md +++ b/api.md @@ -62,6 +62,7 @@ Methods: Response Types: +- anthropic.DeletedMessageBatch - anthropic.MessageBatch - anthropic.MessageBatchCanceledResult - anthropic.MessageBatchErroredResult @@ -76,6 +77,7 @@ Methods: - client.Messages.Batches.New(ctx context.Context, body anthropic.MessageBatchNewParams) (anthropic.MessageBatch, error) - client.Messages.Batches.Get(ctx context.Context, messageBatchID string) (anthropic.MessageBatch, error) - client.Messages.Batches.List(ctx context.Context, query anthropic.MessageBatchListParams) (pagination.Page[anthropic.MessageBatch], error) +- client.Messages.Batches.Delete(ctx context.Context, messageBatchID string) (anthropic.DeletedMessageBatch, error) - client.Messages.Batches.Cancel(ctx context.Context, messageBatchID string) (anthropic.MessageBatch, error) - client.Messages.Batches.Results(ctx context.Context, messageBatchID string) (http.Response, error) @@ -173,6 +175,7 @@ Methods: Response Types: +- anthropic.BetaDeletedMessageBatch - anthropic.BetaMessageBatch - anthropic.BetaMessageBatchCanceledResult - anthropic.BetaMessageBatchErroredResult @@ -187,5 +190,6 @@ Methods: - client.Beta.Messages.Batches.New(ctx context.Context, params anthropic.BetaMessageBatchNewParams) (anthropic.BetaMessageBatch, error) - client.Beta.Messages.Batches.Get(ctx context.Context, messageBatchID string, query anthropic.BetaMessageBatchGetParams) (anthropic.BetaMessageBatch, error) - client.Beta.Messages.Batches.List(ctx context.Context, params anthropic.BetaMessageBatchListParams) (pagination.Page[anthropic.BetaMessageBatch], error) +- client.Beta.Messages.Batches.Delete(ctx context.Context, messageBatchID string, body anthropic.BetaMessageBatchDeleteParams) (anthropic.BetaDeletedMessageBatch, error) - client.Beta.Messages.Batches.Cancel(ctx context.Context, messageBatchID string, body anthropic.BetaMessageBatchCancelParams) (anthropic.BetaMessageBatch, error) - client.Beta.Messages.Batches.Results(ctx context.Context, messageBatchID string, query anthropic.BetaMessageBatchResultsParams) (http.Response, error) diff --git a/betamessagebatch.go b/betamessagebatch.go index 60a5e10..c75e3d4 100644 --- a/betamessagebatch.go +++ b/betamessagebatch.go @@ -92,6 +92,21 @@ func (r *BetaMessageBatchService) ListAutoPaging(ctx context.Context, params Bet return pagination.NewPageAutoPager(r.List(ctx, params, opts...)) } +// This endpoint is idempotent and can be used to poll for Message Batch +// completion. To access the results of a Message Batch, make a request to the +// `results_url` field in the response. +func (r *BetaMessageBatchService) Delete(ctx context.Context, messageBatchID string, body BetaMessageBatchDeleteParams, opts ...option.RequestOption) (res *BetaDeletedMessageBatch, err error) { + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) + if messageBatchID == "" { + err = errors.New("missing required message_batch_id parameter") + return + } + path := fmt.Sprintf("v1/messages/batches/%s?beta=true", messageBatchID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) + return +} + // Batches may be canceled any time before processing ends. Once cancellation is // initiated, the batch enters a `canceling` state, at which time the system may // complete any in-progress, non-interruptible requests before finalizing @@ -130,6 +145,50 @@ func (r *BetaMessageBatchService) Results(ctx context.Context, messageBatchID st return } +type BetaDeletedMessageBatch struct { + // ID of the Message Batch. + ID string `json:"id,required"` + // Deleted object type. + // + // For Message Batches, this is always `"message_batch_deleted"`. + Type BetaDeletedMessageBatchType `json:"type,required"` + JSON betaDeletedMessageBatchJSON `json:"-"` +} + +// betaDeletedMessageBatchJSON contains the JSON metadata for the struct +// [BetaDeletedMessageBatch] +type betaDeletedMessageBatchJSON struct { + ID apijson.Field + Type apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *BetaDeletedMessageBatch) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r betaDeletedMessageBatchJSON) RawJSON() string { + return r.raw +} + +// Deleted object type. +// +// For Message Batches, this is always `"message_batch_deleted"`. +type BetaDeletedMessageBatchType string + +const ( + BetaDeletedMessageBatchTypeMessageBatchDeleted BetaDeletedMessageBatchType = "message_batch_deleted" +) + +func (r BetaDeletedMessageBatchType) IsKnown() bool { + switch r { + case BetaDeletedMessageBatchTypeMessageBatchDeleted: + return true + } + return false +} + type BetaMessageBatch struct { // Unique object identifier. // @@ -864,6 +923,11 @@ func (r BetaMessageBatchListParams) URLQuery() (v url.Values) { }) } +type BetaMessageBatchDeleteParams struct { + // Optional header to specify the beta version(s) you want to use. + Betas param.Field[[]AnthropicBeta] `header:"anthropic-beta"` +} + type BetaMessageBatchCancelParams struct { // Optional header to specify the beta version(s) you want to use. Betas param.Field[[]AnthropicBeta] `header:"anthropic-beta"` diff --git a/betamessagebatch_test.go b/betamessagebatch_test.go index 00fbe64..6c19949 100644 --- a/betamessagebatch_test.go +++ b/betamessagebatch_test.go @@ -141,6 +141,34 @@ func TestBetaMessageBatchListWithOptionalParams(t *testing.T) { } } +func TestBetaMessageBatchDeleteWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := anthropic.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("my-anthropic-api-key"), + ) + _, err := client.Beta.Messages.Batches.Delete( + context.TODO(), + "message_batch_id", + anthropic.BetaMessageBatchDeleteParams{ + Betas: anthropic.F([]anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}), + }, + ) + if err != nil { + var apierr *anthropic.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + func TestBetaMessageBatchCancelWithOptionalParams(t *testing.T) { baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { diff --git a/messagebatch.go b/messagebatch.go index 60a2598..c9ed5de 100644 --- a/messagebatch.go +++ b/messagebatch.go @@ -91,6 +91,20 @@ func (r *MessageBatchService) ListAutoPaging(ctx context.Context, query MessageB return pagination.NewPageAutoPager(r.List(ctx, query, opts...)) } +// This endpoint is idempotent and can be used to poll for Message Batch +// completion. To access the results of a Message Batch, make a request to the +// `results_url` field in the response. +func (r *MessageBatchService) Delete(ctx context.Context, messageBatchID string, opts ...option.RequestOption) (res *DeletedMessageBatch, err error) { + opts = append(r.Options[:], opts...) + if messageBatchID == "" { + err = errors.New("missing required message_batch_id parameter") + return + } + path := fmt.Sprintf("v1/messages/batches/%s", messageBatchID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) + return +} + // Batches may be canceled any time before processing ends. Once cancellation is // initiated, the batch enters a `canceling` state, at which time the system may // complete any in-progress, non-interruptible requests before finalizing @@ -128,6 +142,50 @@ func (r *MessageBatchService) Results(ctx context.Context, messageBatchID string return } +type DeletedMessageBatch struct { + // ID of the Message Batch. + ID string `json:"id,required"` + // Deleted object type. + // + // For Message Batches, this is always `"message_batch_deleted"`. + Type DeletedMessageBatchType `json:"type,required"` + JSON deletedMessageBatchJSON `json:"-"` +} + +// deletedMessageBatchJSON contains the JSON metadata for the struct +// [DeletedMessageBatch] +type deletedMessageBatchJSON struct { + ID apijson.Field + Type apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DeletedMessageBatch) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r deletedMessageBatchJSON) RawJSON() string { + return r.raw +} + +// Deleted object type. +// +// For Message Batches, this is always `"message_batch_deleted"`. +type DeletedMessageBatchType string + +const ( + DeletedMessageBatchTypeMessageBatchDeleted DeletedMessageBatchType = "message_batch_deleted" +) + +func (r DeletedMessageBatchType) IsKnown() bool { + switch r { + case DeletedMessageBatchTypeMessageBatchDeleted: + return true + } + return false +} + type MessageBatch struct { // Unique object identifier. // diff --git a/messagebatch_test.go b/messagebatch_test.go index ad7a8e4..3b9cbb5 100644 --- a/messagebatch_test.go +++ b/messagebatch_test.go @@ -130,6 +130,28 @@ func TestMessageBatchListWithOptionalParams(t *testing.T) { } } +func TestMessageBatchDelete(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := anthropic.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("my-anthropic-api-key"), + ) + _, err := client.Messages.Batches.Delete(context.TODO(), "message_batch_id") + if err != nil { + var apierr *anthropic.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + func TestMessageBatchCancel(t *testing.T) { baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { From c8ddc6b1364485e299e050423e459023e2d65b46 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 01:53:52 +0000 Subject: [PATCH 2/7] chore: bump license year (#88) --- betamessage.go | 10 ++++++++++ betamessagebatch.go | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/betamessage.go b/betamessage.go index c723958..568c658 100644 --- a/betamessage.go +++ b/betamessage.go @@ -4,6 +4,7 @@ package anthropic import ( "context" + "fmt" "net/http" "reflect" @@ -44,6 +45,9 @@ func NewBetaMessageService(opts ...option.RequestOption) (r *BetaMessageService) // // Note: If you choose to set a timeout for this request, we recommend 10 minutes. func (r *BetaMessageService) New(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (res *BetaMessage, err error) { + if params.Betas.Present { + opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + } opts = append(r.Options[:], opts...) path := "v1/messages?beta=true" err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) @@ -62,6 +66,9 @@ func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessag raw *http.Response err error ) + if params.Betas.Present { + opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...) path := "v1/messages?beta=true" @@ -74,6 +81,9 @@ func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessag // The Token Count API can be used to count the number of tokens in a Message, // including tools, images, and documents, without creating it. func (r *BetaMessageService) CountTokens(ctx context.Context, params BetaMessageCountTokensParams, opts ...option.RequestOption) (res *BetaMessageTokensCount, err error) { + if params.Betas.Present { + opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + } opts = append(r.Options[:], opts...) path := "v1/messages/count_tokens?beta=true" err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) diff --git a/betamessagebatch.go b/betamessagebatch.go index c75e3d4..ee47c55 100644 --- a/betamessagebatch.go +++ b/betamessagebatch.go @@ -45,6 +45,9 @@ func NewBetaMessageBatchService(opts ...option.RequestOption) (r *BetaMessageBat // once. Once a Message Batch is created, it begins processing immediately. Batches // can take up to 24 hours to complete. func (r *BetaMessageBatchService) New(ctx context.Context, params BetaMessageBatchNewParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) { + if params.Betas.Present { + opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) path := "v1/messages/batches?beta=true" @@ -56,6 +59,9 @@ func (r *BetaMessageBatchService) New(ctx context.Context, params BetaMessageBat // completion. To access the results of a Message Batch, make a request to the // `results_url` field in the response. func (r *BetaMessageBatchService) Get(ctx context.Context, messageBatchID string, query BetaMessageBatchGetParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) { + if query.Betas.Present { + opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", query.Betas))) + } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) if messageBatchID == "" { @@ -71,6 +77,9 @@ func (r *BetaMessageBatchService) Get(ctx context.Context, messageBatchID string // returned first. func (r *BetaMessageBatchService) List(ctx context.Context, params BetaMessageBatchListParams, opts ...option.RequestOption) (res *pagination.Page[BetaMessageBatch], err error) { var raw *http.Response + if params.Betas.Present { + opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24"), option.WithResponseInto(&raw)}, opts...) path := "v1/messages/batches?beta=true" @@ -96,6 +105,9 @@ func (r *BetaMessageBatchService) ListAutoPaging(ctx context.Context, params Bet // completion. To access the results of a Message Batch, make a request to the // `results_url` field in the response. func (r *BetaMessageBatchService) Delete(ctx context.Context, messageBatchID string, body BetaMessageBatchDeleteParams, opts ...option.RequestOption) (res *BetaDeletedMessageBatch, err error) { + if body.Betas.Present { + opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", body.Betas))) + } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) if messageBatchID == "" { @@ -117,6 +129,9 @@ func (r *BetaMessageBatchService) Delete(ctx context.Context, messageBatchID str // Note that cancellation may not result in any canceled requests if they were // non-interruptible. func (r *BetaMessageBatchService) Cancel(ctx context.Context, messageBatchID string, body BetaMessageBatchCancelParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) { + if body.Betas.Present { + opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", body.Betas))) + } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) if messageBatchID == "" { @@ -134,6 +149,9 @@ func (r *BetaMessageBatchService) Cancel(ctx context.Context, messageBatchID str // in the Message Batch. Results are not guaranteed to be in the same order as // requests. Use the `custom_id` field to match results to requests. func (r *BetaMessageBatchService) Results(ctx context.Context, messageBatchID string, query BetaMessageBatchResultsParams, opts ...option.RequestOption) (res *http.Response, err error) { + if query.Betas.Present { + opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", query.Betas))) + } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24"), option.WithHeader("Accept", "application/binary")}, opts...) if messageBatchID == "" { From d728bcc9d69414bb3ba577e504e1285f0eb22bc5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 02:22:01 +0000 Subject: [PATCH 3/7] fix: support array query parameters (#89) --- betamessage.go | 12 ++++++------ betamessagebatch.go | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/betamessage.go b/betamessage.go index 568c658..4f48ddc 100644 --- a/betamessage.go +++ b/betamessage.go @@ -45,8 +45,8 @@ func NewBetaMessageService(opts ...option.RequestOption) (r *BetaMessageService) // // Note: If you choose to set a timeout for this request, we recommend 10 minutes. func (r *BetaMessageService) New(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (res *BetaMessage, err error) { - if params.Betas.Present { - opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + for _, v := range params.Betas.Value { + opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) path := "v1/messages?beta=true" @@ -66,8 +66,8 @@ func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessag raw *http.Response err error ) - if params.Betas.Present { - opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + for _, v := range params.Betas.Value { + opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...) @@ -81,8 +81,8 @@ func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessag // The Token Count API can be used to count the number of tokens in a Message, // including tools, images, and documents, without creating it. func (r *BetaMessageService) CountTokens(ctx context.Context, params BetaMessageCountTokensParams, opts ...option.RequestOption) (res *BetaMessageTokensCount, err error) { - if params.Betas.Present { - opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + for _, v := range params.Betas.Value { + opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) path := "v1/messages/count_tokens?beta=true" diff --git a/betamessagebatch.go b/betamessagebatch.go index ee47c55..de0c905 100644 --- a/betamessagebatch.go +++ b/betamessagebatch.go @@ -45,8 +45,8 @@ func NewBetaMessageBatchService(opts ...option.RequestOption) (r *BetaMessageBat // once. Once a Message Batch is created, it begins processing immediately. Batches // can take up to 24 hours to complete. func (r *BetaMessageBatchService) New(ctx context.Context, params BetaMessageBatchNewParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) { - if params.Betas.Present { - opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + for _, v := range params.Betas.Value { + opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) @@ -59,8 +59,8 @@ func (r *BetaMessageBatchService) New(ctx context.Context, params BetaMessageBat // completion. To access the results of a Message Batch, make a request to the // `results_url` field in the response. func (r *BetaMessageBatchService) Get(ctx context.Context, messageBatchID string, query BetaMessageBatchGetParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) { - if query.Betas.Present { - opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", query.Betas))) + for _, v := range query.Betas.Value { + opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) @@ -77,8 +77,8 @@ func (r *BetaMessageBatchService) Get(ctx context.Context, messageBatchID string // returned first. func (r *BetaMessageBatchService) List(ctx context.Context, params BetaMessageBatchListParams, opts ...option.RequestOption) (res *pagination.Page[BetaMessageBatch], err error) { var raw *http.Response - if params.Betas.Present { - opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", params.Betas))) + for _, v := range params.Betas.Value { + opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24"), option.WithResponseInto(&raw)}, opts...) @@ -105,8 +105,8 @@ func (r *BetaMessageBatchService) ListAutoPaging(ctx context.Context, params Bet // completion. To access the results of a Message Batch, make a request to the // `results_url` field in the response. func (r *BetaMessageBatchService) Delete(ctx context.Context, messageBatchID string, body BetaMessageBatchDeleteParams, opts ...option.RequestOption) (res *BetaDeletedMessageBatch, err error) { - if body.Betas.Present { - opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", body.Betas))) + for _, v := range body.Betas.Value { + opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) @@ -129,8 +129,8 @@ func (r *BetaMessageBatchService) Delete(ctx context.Context, messageBatchID str // Note that cancellation may not result in any canceled requests if they were // non-interruptible. func (r *BetaMessageBatchService) Cancel(ctx context.Context, messageBatchID string, body BetaMessageBatchCancelParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) { - if body.Betas.Present { - opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", body.Betas))) + for _, v := range body.Betas.Value { + opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) @@ -149,8 +149,8 @@ func (r *BetaMessageBatchService) Cancel(ctx context.Context, messageBatchID str // in the Message Batch. Results are not guaranteed to be in the same order as // requests. Use the `custom_id` field to match results to requests. func (r *BetaMessageBatchService) Results(ctx context.Context, messageBatchID string, query BetaMessageBatchResultsParams, opts ...option.RequestOption) (res *http.Response, err error) { - if query.Betas.Present { - opts = append(opts, option.WithHeader("betas", fmt.Sprintf("%s", query.Betas))) + for _, v := range query.Betas.Value { + opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24"), option.WithHeader("Accept", "application/binary")}, opts...) From d52699aa2036162f6842a3115eb754b6870260e1 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 3 Jan 2025 05:32:06 +0000 Subject: [PATCH 4/7] fix: fix header parameter value (#90) --- betamessage.go | 6 +++--- betamessagebatch.go | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/betamessage.go b/betamessage.go index 4f48ddc..8e71df0 100644 --- a/betamessage.go +++ b/betamessage.go @@ -46,7 +46,7 @@ func NewBetaMessageService(opts ...option.RequestOption) (r *BetaMessageService) // Note: If you choose to set a timeout for this request, we recommend 10 minutes. func (r *BetaMessageService) New(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (res *BetaMessage, err error) { for _, v := range params.Betas.Value { - opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) path := "v1/messages?beta=true" @@ -67,7 +67,7 @@ func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessag err error ) for _, v := range params.Betas.Value { - opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...) @@ -82,7 +82,7 @@ func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessag // including tools, images, and documents, without creating it. func (r *BetaMessageService) CountTokens(ctx context.Context, params BetaMessageCountTokensParams, opts ...option.RequestOption) (res *BetaMessageTokensCount, err error) { for _, v := range params.Betas.Value { - opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) path := "v1/messages/count_tokens?beta=true" diff --git a/betamessagebatch.go b/betamessagebatch.go index de0c905..242d744 100644 --- a/betamessagebatch.go +++ b/betamessagebatch.go @@ -46,7 +46,7 @@ func NewBetaMessageBatchService(opts ...option.RequestOption) (r *BetaMessageBat // can take up to 24 hours to complete. func (r *BetaMessageBatchService) New(ctx context.Context, params BetaMessageBatchNewParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) { for _, v := range params.Betas.Value { - opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) @@ -60,7 +60,7 @@ func (r *BetaMessageBatchService) New(ctx context.Context, params BetaMessageBat // `results_url` field in the response. func (r *BetaMessageBatchService) Get(ctx context.Context, messageBatchID string, query BetaMessageBatchGetParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) { for _, v := range query.Betas.Value { - opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) @@ -78,7 +78,7 @@ func (r *BetaMessageBatchService) Get(ctx context.Context, messageBatchID string func (r *BetaMessageBatchService) List(ctx context.Context, params BetaMessageBatchListParams, opts ...option.RequestOption) (res *pagination.Page[BetaMessageBatch], err error) { var raw *http.Response for _, v := range params.Betas.Value { - opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24"), option.WithResponseInto(&raw)}, opts...) @@ -106,7 +106,7 @@ func (r *BetaMessageBatchService) ListAutoPaging(ctx context.Context, params Bet // `results_url` field in the response. func (r *BetaMessageBatchService) Delete(ctx context.Context, messageBatchID string, body BetaMessageBatchDeleteParams, opts ...option.RequestOption) (res *BetaDeletedMessageBatch, err error) { for _, v := range body.Betas.Value { - opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) @@ -130,7 +130,7 @@ func (r *BetaMessageBatchService) Delete(ctx context.Context, messageBatchID str // non-interruptible. func (r *BetaMessageBatchService) Cancel(ctx context.Context, messageBatchID string, body BetaMessageBatchCancelParams, opts ...option.RequestOption) (res *BetaMessageBatch, err error) { for _, v := range body.Betas.Value { - opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24")}, opts...) @@ -150,7 +150,7 @@ func (r *BetaMessageBatchService) Cancel(ctx context.Context, messageBatchID str // requests. Use the `custom_id` field to match results to requests. func (r *BetaMessageBatchService) Results(ctx context.Context, messageBatchID string, query BetaMessageBatchResultsParams, opts ...option.RequestOption) (res *http.Response, err error) { for _, v := range query.Betas.Value { - opts = append(opts, option.WithHeaderAdd("betas", fmt.Sprintf("%s", v))) + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v))) } opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "message-batches-2024-09-24"), option.WithHeader("Accept", "application/binary")}, opts...) From 97176628489158be07baf1747ba39f15429d3a39 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:05:19 +0000 Subject: [PATCH 5/7] chore(internal): update examples (#91) --- betamessage_test.go | 4 ++-- betamessagebatch_test.go | 2 +- message_test.go | 5 ++++- messagebatch_test.go | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/betamessage_test.go b/betamessage_test.go index 71a8f24..f0b4f9e 100644 --- a/betamessage_test.go +++ b/betamessage_test.go @@ -56,7 +56,7 @@ func TestBetaMessageNewWithOptionalParams(t *testing.T) { }, }), }), - Name: anthropic.F("x"), + Name: anthropic.F("name"), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{ Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral), }), @@ -119,7 +119,7 @@ func TestBetaMessageCountTokensWithOptionalParams(t *testing.T) { }, }), }), - Name: anthropic.F("x"), + Name: anthropic.F("name"), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{ Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral), }), diff --git a/betamessagebatch_test.go b/betamessagebatch_test.go index 6c19949..39bc834 100644 --- a/betamessagebatch_test.go +++ b/betamessagebatch_test.go @@ -64,7 +64,7 @@ func TestBetaMessageBatchNewWithOptionalParams(t *testing.T) { }, }), }), - Name: anthropic.F("x"), + Name: anthropic.F("name"), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{ Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral), }), diff --git a/message_test.go b/message_test.go index 77c111a..15f5b11 100644 --- a/message_test.go +++ b/message_test.go @@ -58,6 +58,9 @@ func TestMessageNewWithOptionalParams(t *testing.T) { }, }, }), + CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{ + Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral), + }), }}), TopK: anthropic.F(int64(5)), TopP: anthropic.F(0.700000), @@ -114,7 +117,7 @@ func TestMessageCountTokensWithOptionalParams(t *testing.T) { }, }, }), - Name: anthropic.F("x"), + Name: anthropic.F("name"), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{ Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral), }), diff --git a/messagebatch_test.go b/messagebatch_test.go index 3b9cbb5..25dd600 100644 --- a/messagebatch_test.go +++ b/messagebatch_test.go @@ -62,7 +62,7 @@ func TestMessageBatchNew(t *testing.T) { "type": "string", }, }}), - Name: anthropic.F("x"), + Name: anthropic.F("name"), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{ Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral), }), From 953d5104b1460b749b776a6ba4df90d2604c06cd Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:22:11 +0000 Subject: [PATCH 6/7] docs(readme): fix misplaced period (#93) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5fe3da5..a0ff9f1 100644 --- a/README.md +++ b/README.md @@ -635,7 +635,7 @@ Read more about Anthropic and Google Vertex [here](https://docs.anthropic.com/en This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions: -1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_. +1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_ 2. Changes that we do not expect to impact the vast majority of users in practice. We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience. From ae65a372db9d67006ed9cc49e63ad6ad6ee413ce Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 15 Jan 2025 05:04:37 +0000 Subject: [PATCH 7/7] release: 0.2.0-alpha.9 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 25 +++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index caa6bf0..96e1bc4 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0-alpha.8" + ".": "0.2.0-alpha.9" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 90a382d..c67eb49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## 0.2.0-alpha.9 (2025-01-15) + +Full Changelog: [v0.2.0-alpha.8...v0.2.0-alpha.9](https://github.com/anthropics/anthropic-sdk-go/compare/v0.2.0-alpha.8...v0.2.0-alpha.9) + +### Features + +* **api:** add message batch delete endpoint ([#81](https://github.com/anthropics/anthropic-sdk-go/issues/81)) ([b3a63e7](https://github.com/anthropics/anthropic-sdk-go/commit/b3a63e7cbf73d06141750cf126af25412b12061d)) + + +### Bug Fixes + +* fix header parameter value ([#90](https://github.com/anthropics/anthropic-sdk-go/issues/90)) ([d52699a](https://github.com/anthropics/anthropic-sdk-go/commit/d52699aa2036162f6842a3115eb754b6870260e1)) +* support array query parameters ([#89](https://github.com/anthropics/anthropic-sdk-go/issues/89)) ([d728bcc](https://github.com/anthropics/anthropic-sdk-go/commit/d728bcc9d69414bb3ba577e504e1285f0eb22bc5)) + + +### Chores + +* bump license year ([#88](https://github.com/anthropics/anthropic-sdk-go/issues/88)) ([c8ddc6b](https://github.com/anthropics/anthropic-sdk-go/commit/c8ddc6b1364485e299e050423e459023e2d65b46)) +* **internal:** update examples ([#91](https://github.com/anthropics/anthropic-sdk-go/issues/91)) ([9717662](https://github.com/anthropics/anthropic-sdk-go/commit/97176628489158be07baf1747ba39f15429d3a39)) + + +### Documentation + +* **readme:** fix misplaced period ([#93](https://github.com/anthropics/anthropic-sdk-go/issues/93)) ([953d510](https://github.com/anthropics/anthropic-sdk-go/commit/953d5104b1460b749b776a6ba4df90d2604c06cd)) + ## 0.2.0-alpha.8 (2024-12-19) Full Changelog: [v0.2.0-alpha.7...v0.2.0-alpha.8](https://github.com/anthropics/anthropic-sdk-go/compare/v0.2.0-alpha.7...v0.2.0-alpha.8) diff --git a/README.md b/README.md index a0ff9f1..2facac5 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Or to pin the version: ```sh -go get -u 'github.com/anthropics/anthropic-sdk-go@v0.2.0-alpha.8' +go get -u 'github.com/anthropics/anthropic-sdk-go@v0.2.0-alpha.9' ```