beta.go

  1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2
  3package anthropic
  4
  5import (
  6	"encoding/json"
  7
  8	"github.com/anthropics/anthropic-sdk-go/internal/apijson"
  9	"github.com/anthropics/anthropic-sdk-go/option"
 10	"github.com/anthropics/anthropic-sdk-go/packages/respjson"
 11	"github.com/anthropics/anthropic-sdk-go/shared/constant"
 12)
 13
 14// BetaService contains methods and other services that help with interacting with
 15// the anthropic API.
 16//
 17// Note, unlike clients, this service does not read variables from the environment
 18// automatically. You should not instantiate this service directly, and instead use
 19// the [NewBetaService] method instead.
 20type BetaService struct {
 21	Options  []option.RequestOption
 22	Models   BetaModelService
 23	Messages BetaMessageService
 24	Files    BetaFileService
 25}
 26
 27// NewBetaService generates a new service that applies the given options to each
 28// request. These options are applied after the parent client's options (if there
 29// is one), and before any request-specific options.
 30func NewBetaService(opts ...option.RequestOption) (r BetaService) {
 31	r = BetaService{}
 32	r.Options = opts
 33	r.Models = NewBetaModelService(opts...)
 34	r.Messages = NewBetaMessageService(opts...)
 35	r.Files = NewBetaFileService(opts...)
 36	return
 37}
 38
 39type AnthropicBeta = string
 40
 41const (
 42	AnthropicBetaMessageBatches2024_09_24      AnthropicBeta = "message-batches-2024-09-24"
 43	AnthropicBetaPromptCaching2024_07_31       AnthropicBeta = "prompt-caching-2024-07-31"
 44	AnthropicBetaComputerUse2024_10_22         AnthropicBeta = "computer-use-2024-10-22"
 45	AnthropicBetaComputerUse2025_01_24         AnthropicBeta = "computer-use-2025-01-24"
 46	AnthropicBetaPDFs2024_09_25                AnthropicBeta = "pdfs-2024-09-25"
 47	AnthropicBetaTokenCounting2024_11_01       AnthropicBeta = "token-counting-2024-11-01"
 48	AnthropicBetaTokenEfficientTools2025_02_19 AnthropicBeta = "token-efficient-tools-2025-02-19"
 49	AnthropicBetaOutput128k2025_02_19          AnthropicBeta = "output-128k-2025-02-19"
 50	AnthropicBetaFilesAPI2025_04_14            AnthropicBeta = "files-api-2025-04-14"
 51	AnthropicBetaMCPClient2025_04_04           AnthropicBeta = "mcp-client-2025-04-04"
 52	AnthropicBetaDevFullThinking2025_05_14     AnthropicBeta = "dev-full-thinking-2025-05-14"
 53	AnthropicBetaInterleavedThinking2025_05_14 AnthropicBeta = "interleaved-thinking-2025-05-14"
 54	AnthropicBetaCodeExecution2025_05_22       AnthropicBeta = "code-execution-2025-05-22"
 55	AnthropicBetaExtendedCacheTTL2025_04_11    AnthropicBeta = "extended-cache-ttl-2025-04-11"
 56)
 57
 58type BetaAPIError struct {
 59	Message string            `json:"message,required"`
 60	Type    constant.APIError `json:"type,required"`
 61	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 62	JSON struct {
 63		Message     respjson.Field
 64		Type        respjson.Field
 65		ExtraFields map[string]respjson.Field
 66		raw         string
 67	} `json:"-"`
 68}
 69
 70// Returns the unmodified JSON received from the API
 71func (r BetaAPIError) RawJSON() string { return r.JSON.raw }
 72func (r *BetaAPIError) UnmarshalJSON(data []byte) error {
 73	return apijson.UnmarshalRoot(data, r)
 74}
 75
 76type BetaAuthenticationError struct {
 77	Message string                       `json:"message,required"`
 78	Type    constant.AuthenticationError `json:"type,required"`
 79	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 80	JSON struct {
 81		Message     respjson.Field
 82		Type        respjson.Field
 83		ExtraFields map[string]respjson.Field
 84		raw         string
 85	} `json:"-"`
 86}
 87
 88// Returns the unmodified JSON received from the API
 89func (r BetaAuthenticationError) RawJSON() string { return r.JSON.raw }
 90func (r *BetaAuthenticationError) UnmarshalJSON(data []byte) error {
 91	return apijson.UnmarshalRoot(data, r)
 92}
 93
 94type BetaBillingError struct {
 95	Message string                `json:"message,required"`
 96	Type    constant.BillingError `json:"type,required"`
 97	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 98	JSON struct {
 99		Message     respjson.Field
100		Type        respjson.Field
101		ExtraFields map[string]respjson.Field
102		raw         string
103	} `json:"-"`
104}
105
106// Returns the unmodified JSON received from the API
107func (r BetaBillingError) RawJSON() string { return r.JSON.raw }
108func (r *BetaBillingError) UnmarshalJSON(data []byte) error {
109	return apijson.UnmarshalRoot(data, r)
110}
111
112// BetaErrorUnion contains all possible properties and values from
113// [BetaInvalidRequestError], [BetaAuthenticationError], [BetaBillingError],
114// [BetaPermissionError], [BetaNotFoundError], [BetaRateLimitError],
115// [BetaGatewayTimeoutError], [BetaAPIError], [BetaOverloadedError].
116//
117// Use the [BetaErrorUnion.AsAny] method to switch on the variant.
118//
119// Use the methods beginning with 'As' to cast the union to one of its variants.
120type BetaErrorUnion struct {
121	Message string `json:"message"`
122	// Any of "invalid_request_error", "authentication_error", "billing_error",
123	// "permission_error", "not_found_error", "rate_limit_error", "timeout_error",
124	// "api_error", "overloaded_error".
125	Type string `json:"type"`
126	JSON struct {
127		Message respjson.Field
128		Type    respjson.Field
129		raw     string
130	} `json:"-"`
131}
132
133// anyBetaError is implemented by each variant of [BetaErrorUnion] to add type
134// safety for the return type of [BetaErrorUnion.AsAny]
135type anyBetaError interface {
136	implBetaErrorUnion()
137}
138
139func (BetaInvalidRequestError) implBetaErrorUnion() {}
140func (BetaAuthenticationError) implBetaErrorUnion() {}
141func (BetaBillingError) implBetaErrorUnion()        {}
142func (BetaPermissionError) implBetaErrorUnion()     {}
143func (BetaNotFoundError) implBetaErrorUnion()       {}
144func (BetaRateLimitError) implBetaErrorUnion()      {}
145func (BetaGatewayTimeoutError) implBetaErrorUnion() {}
146func (BetaAPIError) implBetaErrorUnion()            {}
147func (BetaOverloadedError) implBetaErrorUnion()     {}
148
149// Use the following switch statement to find the correct variant
150//
151//	switch variant := BetaErrorUnion.AsAny().(type) {
152//	case anthropic.BetaInvalidRequestError:
153//	case anthropic.BetaAuthenticationError:
154//	case anthropic.BetaBillingError:
155//	case anthropic.BetaPermissionError:
156//	case anthropic.BetaNotFoundError:
157//	case anthropic.BetaRateLimitError:
158//	case anthropic.BetaGatewayTimeoutError:
159//	case anthropic.BetaAPIError:
160//	case anthropic.BetaOverloadedError:
161//	default:
162//	  fmt.Errorf("no variant present")
163//	}
164func (u BetaErrorUnion) AsAny() anyBetaError {
165	switch u.Type {
166	case "invalid_request_error":
167		return u.AsInvalidRequestError()
168	case "authentication_error":
169		return u.AsAuthenticationError()
170	case "billing_error":
171		return u.AsBillingError()
172	case "permission_error":
173		return u.AsPermissionError()
174	case "not_found_error":
175		return u.AsNotFoundError()
176	case "rate_limit_error":
177		return u.AsRateLimitError()
178	case "timeout_error":
179		return u.AsTimeoutError()
180	case "api_error":
181		return u.AsAPIError()
182	case "overloaded_error":
183		return u.AsOverloadedError()
184	}
185	return nil
186}
187
188func (u BetaErrorUnion) AsInvalidRequestError() (v BetaInvalidRequestError) {
189	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
190	return
191}
192
193func (u BetaErrorUnion) AsAuthenticationError() (v BetaAuthenticationError) {
194	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
195	return
196}
197
198func (u BetaErrorUnion) AsBillingError() (v BetaBillingError) {
199	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
200	return
201}
202
203func (u BetaErrorUnion) AsPermissionError() (v BetaPermissionError) {
204	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
205	return
206}
207
208func (u BetaErrorUnion) AsNotFoundError() (v BetaNotFoundError) {
209	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
210	return
211}
212
213func (u BetaErrorUnion) AsRateLimitError() (v BetaRateLimitError) {
214	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
215	return
216}
217
218func (u BetaErrorUnion) AsTimeoutError() (v BetaGatewayTimeoutError) {
219	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
220	return
221}
222
223func (u BetaErrorUnion) AsAPIError() (v BetaAPIError) {
224	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
225	return
226}
227
228func (u BetaErrorUnion) AsOverloadedError() (v BetaOverloadedError) {
229	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
230	return
231}
232
233// Returns the unmodified JSON received from the API
234func (u BetaErrorUnion) RawJSON() string { return u.JSON.raw }
235
236func (r *BetaErrorUnion) UnmarshalJSON(data []byte) error {
237	return apijson.UnmarshalRoot(data, r)
238}
239
240type BetaErrorResponse struct {
241	Error BetaErrorUnion `json:"error,required"`
242	Type  constant.Error `json:"type,required"`
243	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
244	JSON struct {
245		Error       respjson.Field
246		Type        respjson.Field
247		ExtraFields map[string]respjson.Field
248		raw         string
249	} `json:"-"`
250}
251
252// Returns the unmodified JSON received from the API
253func (r BetaErrorResponse) RawJSON() string { return r.JSON.raw }
254func (r *BetaErrorResponse) UnmarshalJSON(data []byte) error {
255	return apijson.UnmarshalRoot(data, r)
256}
257
258type BetaGatewayTimeoutError struct {
259	Message string                `json:"message,required"`
260	Type    constant.TimeoutError `json:"type,required"`
261	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
262	JSON struct {
263		Message     respjson.Field
264		Type        respjson.Field
265		ExtraFields map[string]respjson.Field
266		raw         string
267	} `json:"-"`
268}
269
270// Returns the unmodified JSON received from the API
271func (r BetaGatewayTimeoutError) RawJSON() string { return r.JSON.raw }
272func (r *BetaGatewayTimeoutError) UnmarshalJSON(data []byte) error {
273	return apijson.UnmarshalRoot(data, r)
274}
275
276type BetaInvalidRequestError struct {
277	Message string                       `json:"message,required"`
278	Type    constant.InvalidRequestError `json:"type,required"`
279	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
280	JSON struct {
281		Message     respjson.Field
282		Type        respjson.Field
283		ExtraFields map[string]respjson.Field
284		raw         string
285	} `json:"-"`
286}
287
288// Returns the unmodified JSON received from the API
289func (r BetaInvalidRequestError) RawJSON() string { return r.JSON.raw }
290func (r *BetaInvalidRequestError) UnmarshalJSON(data []byte) error {
291	return apijson.UnmarshalRoot(data, r)
292}
293
294type BetaNotFoundError struct {
295	Message string                 `json:"message,required"`
296	Type    constant.NotFoundError `json:"type,required"`
297	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
298	JSON struct {
299		Message     respjson.Field
300		Type        respjson.Field
301		ExtraFields map[string]respjson.Field
302		raw         string
303	} `json:"-"`
304}
305
306// Returns the unmodified JSON received from the API
307func (r BetaNotFoundError) RawJSON() string { return r.JSON.raw }
308func (r *BetaNotFoundError) UnmarshalJSON(data []byte) error {
309	return apijson.UnmarshalRoot(data, r)
310}
311
312type BetaOverloadedError struct {
313	Message string                   `json:"message,required"`
314	Type    constant.OverloadedError `json:"type,required"`
315	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
316	JSON struct {
317		Message     respjson.Field
318		Type        respjson.Field
319		ExtraFields map[string]respjson.Field
320		raw         string
321	} `json:"-"`
322}
323
324// Returns the unmodified JSON received from the API
325func (r BetaOverloadedError) RawJSON() string { return r.JSON.raw }
326func (r *BetaOverloadedError) UnmarshalJSON(data []byte) error {
327	return apijson.UnmarshalRoot(data, r)
328}
329
330type BetaPermissionError struct {
331	Message string                   `json:"message,required"`
332	Type    constant.PermissionError `json:"type,required"`
333	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
334	JSON struct {
335		Message     respjson.Field
336		Type        respjson.Field
337		ExtraFields map[string]respjson.Field
338		raw         string
339	} `json:"-"`
340}
341
342// Returns the unmodified JSON received from the API
343func (r BetaPermissionError) RawJSON() string { return r.JSON.raw }
344func (r *BetaPermissionError) UnmarshalJSON(data []byte) error {
345	return apijson.UnmarshalRoot(data, r)
346}
347
348type BetaRateLimitError struct {
349	Message string                  `json:"message,required"`
350	Type    constant.RateLimitError `json:"type,required"`
351	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
352	JSON struct {
353		Message     respjson.Field
354		Type        respjson.Field
355		ExtraFields map[string]respjson.Field
356		raw         string
357	} `json:"-"`
358}
359
360// Returns the unmodified JSON received from the API
361func (r BetaRateLimitError) RawJSON() string { return r.JSON.raw }
362func (r *BetaRateLimitError) UnmarshalJSON(data []byte) error {
363	return apijson.UnmarshalRoot(data, r)
364}