Debian Codegraph @

betamessagebatch_test.go

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3 package anthropic_test
4
5 import (
6 "context"
7 "errors"
8 "os"
9 "testing"
10
11 "github.com/anthropics/anthropic-sdk-go"
12 "github.com/anthropics/anthropic-sdk-go/internal/testutil"
13 "github.com/anthropics/anthropic-sdk-go/option"
14 )
15
16 func TestBetaMessageBatchNewWithOptionalParams(t *testing.T) {
17 baseURL := "http://localhost:4010"
18 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
19 baseURL = envURL
20 }
21 if !testutil.CheckTestServer(t, baseURL) {
22 return
23 }
24 client := anthropic.NewClient(
25 option.WithBaseURL(baseURL),
26 option.WithAPIKey("my-anthropic-api-key"),
27 )
28 _, err := client.Beta.Messages.Batches.New(context.TODO(), anthropic.BetaMessageBatchNewParams{
29 Requests: []anthropic.BetaMessageBatchNewParamsRequest{{
30 CustomID: "my-custom-id-1",
31 Params: anthropic.BetaMessageBatchNewParamsRequestParams{
32 MaxTokens: 1024,
33 Messages: []anthropic.BetaMessageParam{{
34 Content: []anthropic.BetaContentBlockParamUnion{{
35 OfText: &anthropic.BetaTextBlockParam{
36 Text: "x",
37 CacheControl: anthropic.BetaCacheControlEphemeralParam{
38 TTL: anthropic.BetaCacheControlEphemeralTTLTTL5m,
39 },
40 Citations: []anthropic.BetaTextCitationParamUnion{{
41 OfCharLocation: &anthropic.BetaCitationCharLocationParam{
42 CitedText: "cited_text",
43 DocumentIndex: 0,
44 DocumentTitle: anthropic.String("x"),
45 EndCharIndex: 0,
46 StartCharIndex: 0,
47 },
48 }},
49 },
50 }},
51 Role: anthropic.BetaMessageParamRoleUser,
52 }},
53 Model: anthropic.ModelClaudeOpus4_6,
54 CacheControl: anthropic.BetaCacheControlEphemeralParam{
55 TTL: anthropic.BetaCacheControlEphemeralTTLTTL5m,
56 },
57 Container: anthropic.BetaMessageBatchNewParamsRequestParamsContainerUnion{
58 OfContainers: &anthropic.BetaContainerParams{
59 ID: anthropic.String("id"),
60 Skills: []anthropic.BetaSkillParams{{
61 SkillID: "pdf",
62 Type: anthropic.BetaSkillParamsTypeAnthropic,
63 Version: anthropic.String("latest"),
64 }},
65 },
66 },
67 ContextManagement: anthropic.BetaContextManagementConfigParam{
68 Edits: []anthropic.BetaContextManagementConfigEditUnionParam{{
69 OfClearToolUses20250919: &anthropic.BetaClearToolUses20250919EditParam{
70 ClearAtLeast: anthropic.BetaInputTokensClearAtLeastParam{
71 Value: 0,
72 },
73 ClearToolInputs: anthropic.BetaClearToolUses20250919EditClearToolInputsUnionParam{
74 OfBool: anthropic.Bool(true),
75 },
76 ExcludeTools: []string{"string"},
77 Keep: anthropic.BetaToolUsesKeepParam{
78 Value: 0,
79 },
80 Trigger: anthropic.BetaClearToolUses20250919EditTriggerUnionParam{
81 OfInputTokens: &anthropic.BetaInputTokensTriggerParam{
82 Value: 1,
83 },
84 },
85 },
86 }},
87 },
88 InferenceGeo: anthropic.String("inference_geo"),
89 MCPServers: []anthropic.BetaRequestMCPServerURLDefinitionParam{{
90 Name: "name",
91 URL: "url",
92 AuthorizationToken: anthropic.String("authorization_token"),
93 ToolConfiguration: anthropic.BetaRequestMCPServerToolConfigurationParam{
94 AllowedTools: []string{"string"},
95 Enabled: anthropic.Bool(true),
96 },
97 }},
98 Metadata: anthropic.BetaMetadataParam{
99 UserID: anthropic.String("13803d75-b4b5-4c3e-b2a2-6f21399b021b"),
100 },
101 OutputConfig: anthropic.BetaOutputConfigParam{
102 Effort: anthropic.BetaOutputConfigEffortLow,
103 Format: anthropic.BetaJSONOutputFormatParam{
104 Schema: map[string]any{
105 "foo": "bar",
106 },
107 },
108 },
109 OutputFormat: anthropic.BetaJSONOutputFormatParam{
110 Schema: map[string]any{
111 "foo": "bar",
112 },
113 },
114 ServiceTier: "auto",
115 Speed: "standard",
116 StopSequences: []string{"string"},
117 Stream: anthropic.Bool(true),
118 System: []anthropic.BetaTextBlockParam{{
119 Text: "Today's date is 2024-06-01.",
120 CacheControl: anthropic.BetaCacheControlEphemeralParam{
121 TTL: anthropic.BetaCacheControlEphemeralTTLTTL5m,
122 },
123 Citations: []anthropic.BetaTextCitationParamUnion{{
124 OfCharLocation: &anthropic.BetaCitationCharLocationParam{
125 CitedText: "cited_text",
126 DocumentIndex: 0,
127 DocumentTitle: anthropic.String("x"),
128 EndCharIndex: 0,
129 StartCharIndex: 0,
130 },
131 }},
132 }},
133 Temperature: anthropic.Float(1),
134 Thinking: anthropic.BetaThinkingConfigParamUnion{
135 OfAdaptive: &anthropic.BetaThinkingConfigAdaptiveParam{
136 Display: anthropic.BetaThinkingConfigAdaptiveDisplaySummarized,
137 },
138 },
139 ToolChoice: anthropic.BetaToolChoiceUnionParam{
140 OfAuto: &anthropic.BetaToolChoiceAutoParam{
141 DisableParallelToolUse: anthropic.Bool(true),
142 },
143 },
144 Tools: []anthropic.BetaToolUnionParam{{
145 OfTool: &anthropic.BetaToolParam{
146 InputSchema: anthropic.BetaToolInputSchemaParam{
147 Properties: map[string]any{
148 "location": "bar",
149 "unit": "bar",
150 },
151 Required: []string{"location"},
152 },
153 Name: "name",
154 AllowedCallers: []string{"direct"},
155 CacheControl: anthropic.BetaCacheControlEphemeralParam{
156 TTL: anthropic.BetaCacheControlEphemeralTTLTTL5m,
157 },
158 DeferLoading: anthropic.Bool(true),
159 Description: anthropic.String("Get the current weather in a given location"),
160 EagerInputStreaming: anthropic.Bool(true),
161 InputExamples: []map[string]any{{
162 "foo": "bar",
163 }},
164 Strict: anthropic.Bool(true),
165 Type: anthropic.BetaToolTypeCustom,
166 },
167 }},
168 TopK: anthropic.Int(5),
169 TopP: anthropic.Float(0.7),
170 },
171 }},
172 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
173 })
174 if err != nil {
175 var apierr *anthropic.Error
176 if errors.As(err, &apierr) {
177 t.Log(string(apierr.DumpRequest(true)))
178 }
179 t.Fatalf("err should be nil: %s", err.Error())
180 }
181 }
182
183 func TestBetaMessageBatchGetWithOptionalParams(t *testing.T) {
184 baseURL := "http://localhost:4010"
185 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
186 baseURL = envURL
187 }
188 if !testutil.CheckTestServer(t, baseURL) {
189 return
190 }
191 client := anthropic.NewClient(
192 option.WithBaseURL(baseURL),
193 option.WithAPIKey("my-anthropic-api-key"),
194 )
195 _, err := client.Beta.Messages.Batches.Get(
196 context.TODO(),
197 "message_batch_id",
198 anthropic.BetaMessageBatchGetParams{
199 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
200 },
201 )
202 if err != nil {
203 var apierr *anthropic.Error
204 if errors.As(err, &apierr) {
205 t.Log(string(apierr.DumpRequest(true)))
206 }
207 t.Fatalf("err should be nil: %s", err.Error())
208 }
209 }
210
211 func TestBetaMessageBatchListWithOptionalParams(t *testing.T) {
212 baseURL := "http://localhost:4010"
213 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
214 baseURL = envURL
215 }
216 if !testutil.CheckTestServer(t, baseURL) {
217 return
218 }
219 client := anthropic.NewClient(
220 option.WithBaseURL(baseURL),
221 option.WithAPIKey("my-anthropic-api-key"),
222 )
223 _, err := client.Beta.Messages.Batches.List(context.TODO(), anthropic.BetaMessageBatchListParams{
224 AfterID: anthropic.String("after_id"),
225 BeforeID: anthropic.String("before_id"),
226 Limit: anthropic.Int(1),
227 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
228 })
229 if err != nil {
230 var apierr *anthropic.Error
231 if errors.As(err, &apierr) {
232 t.Log(string(apierr.DumpRequest(true)))
233 }
234 t.Fatalf("err should be nil: %s", err.Error())
235 }
236 }
237
238 func TestBetaMessageBatchDeleteWithOptionalParams(t *testing.T) {
239 baseURL := "http://localhost:4010"
240 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
241 baseURL = envURL
242 }
243 if !testutil.CheckTestServer(t, baseURL) {
244 return
245 }
246 client := anthropic.NewClient(
247 option.WithBaseURL(baseURL),
248 option.WithAPIKey("my-anthropic-api-key"),
249 )
250 _, err := client.Beta.Messages.Batches.Delete(
251 context.TODO(),
252 "message_batch_id",
253 anthropic.BetaMessageBatchDeleteParams{
254 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
255 },
256 )
257 if err != nil {
258 var apierr *anthropic.Error
259 if errors.As(err, &apierr) {
260 t.Log(string(apierr.DumpRequest(true)))
261 }
262 t.Fatalf("err should be nil: %s", err.Error())
263 }
264 }
265
266 func TestBetaMessageBatchCancelWithOptionalParams(t *testing.T) {
267 baseURL := "http://localhost:4010"
268 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
269 baseURL = envURL
270 }
271 if !testutil.CheckTestServer(t, baseURL) {
272 return
273 }
274 client := anthropic.NewClient(
275 option.WithBaseURL(baseURL),
276 option.WithAPIKey("my-anthropic-api-key"),
277 )
278 _, err := client.Beta.Messages.Batches.Cancel(
279 context.TODO(),
280 "message_batch_id",
281 anthropic.BetaMessageBatchCancelParams{
282 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
283 },
284 )
285 if err != nil {
286 var apierr *anthropic.Error
287 if errors.As(err, &apierr) {
288 t.Log(string(apierr.DumpRequest(true)))
289 }
290 t.Fatalf("err should be nil: %s", err.Error())
291 }
292 }