go changedcli-sdks-libraries/sdks/go
Nearest release: v2.1.307, published an hour after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+21added
Lines−21removed
From line
63
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits11to this page, all time
### Deserializing parameters #### Undocumented request parameters ### Deserializing params #### Undocumented request params
The whole hunk
from line 63, old and new numbered
/
from line 63
6363}
6464```
6565
66For authentication options including Workload Identity Federation, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication). If your API key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) with access to multiple workspaces, set the workspace ID in the `anthropic-workspace-id` request header; [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace) shows the per-request option for this SDK.
66For authentication options including Workload Identity Federation, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication). If your API key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) that isn't scoped to a workspace, set the workspace ID in the `anthropic-workspace-id` request header; [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace) shows the per-request option for this SDK.
6767
6868<AccordionGroup>
6969 <Accordion title="Conversations">
from line 277
277277param.IsNull(p.Point) // true
278278```
279279
280Request structs contain a `.SetExtraFields(map[string]any)` method which can send non-conforming fields in the request body. Extra fields overwrite any struct fields with a matching key.
280Request structs contain a `.SetExtraFields(map[string]any)` method that can send non-conforming fields in the request body. Extra fields overwrite any struct fields with a matching key.
281281
282282<Warning>
283283 For security reasons, only use `SetExtraFields` with trusted data.
from line 298
298298
299299### Request unions
300300
301Unions are represented as a struct with fields prefixed by "Of" for each of its variants. Only one field can be non-zero. The non-zero field will be serialized.
301Unions are represented as a struct with fields prefixed by "Of" for each of its variants. Only one field can be non-zero. The non-zero field is serialized.
302302
303303Subproperties of the union can be accessed through methods on the union struct. These methods return a pointer to the value, if present.
304304
from line 324
324324}
325325```
326326
327### Deserializing params
327### Deserializing parameters
328328
329329<Note>
330330 `param.SetJSON` requires SDK v1.20.0 or later.
331331</Note>
332332
333Param types (types ending in `Param`, such as `MessageNewParams` or `ToolUnionParam`) are designed for outgoing requests only. They marshal correctly to JSON but do not fully support round-trip deserialization. If you unmarshal raw JSON into a param struct, typed union fields like `OfBashTool20250124` will be nil even when the underlying JSON is valid.
333Parameter types (types ending in `Param`, such as `MessageNewParams` or `ToolUnionParam`) are designed for outgoing requests only. They marshal correctly to JSON but do not fully support round-trip deserialization. If you unmarshal raw JSON into a parameter struct, typed union fields such as `OfBashTool20250124` will be nil even when the underlying JSON is valid.
334334
335If you need to reconstruct params from raw JSON (for example, from a database, middleware, or a previous request), call `UnmarshalJSON` to populate non-union fields, then use `param.SetJSON` to attach the raw bytes for correct re-serialization:
335If you need to reconstruct parameters from raw JSON (for example, from a database, middleware, or a previous request), call `UnmarshalJSON` to populate non-union fields, then use `param.SetJSON` to attach the raw bytes for correct re-serialization:
336336
337337```go
338338// Serialize params (for example, for storage or forwarding)
from line 415
415415
416416### Response unions
417417
418In responses, unions are represented by a flattened struct containing all possible fields from each of the object variants. To convert it to a variant use the `.AsFooVariant()` method or the `.AsAny()` method if present.
418In responses, unions are represented by a flattened struct containing all possible fields from each of the object variants. To convert it to a variant, use the `.AsFooVariant()` method or the `.AsAny()` method if present.
419419
420420If a response value union contains primitive values, primitive fields will be alongside the properties but prefixed with `Of` and feature the tag `json:"...,inline"`.
421421
from line 483
483483
484484## Retries
485485
486Certain errors will be automatically retried 2 times by default, with a short exponential backoff. The SDK retries by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors.
486Certain errors are automatically retried 2 times by default, with a short exponential backoff. The SDK retries by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors.
487487
488488You can use the `WithMaxRetries` option to configure or disable this:
489489
from line 546
546546## Long requests
547547
548548<Warning>
549 Consider using the streaming Messages API for longer running requests.
549 Consider using the streaming Messages API for longer-running requests.
550550</Warning>
551551
552Avoid setting a large `MaxTokens` value without using streaming as some networks may drop idle connections after a certain period of time, which can cause the request to fail or [time out](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/go#timeouts) without receiving a response from Anthropic.
552Avoid setting a large `MaxTokens` value without using streaming as some networks might drop idle connections after a certain period of time, which can cause the request to fail or [time out](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/go#timeouts) without receiving a response from Anthropic.
553553
554554This SDK will also return an error if a non-streaming request is expected to be above roughly 10 minutes long. Calling `.Messages.NewStreaming()` or [setting a custom timeout](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/go#timeouts) disables this error.
555555
556556## File uploads
557557
558Request parameters that correspond to file uploads in multipart requests are typed as `io.Reader`. The contents of the `io.Reader` will by default be sent as a multipart form part with the file name of `anonymous_file` and content type of `application/octet-stream`, so the recommended approach is to specify a custom content type with the `anthropic.File(reader io.Reader, filename string, contentType string)` helper, which wraps any `io.Reader` with the appropriate file name and content type.
558Request parameters that correspond to file uploads in multipart requests are typed as `io.Reader`. The contents of the `io.Reader` are sent by default as a multipart form part with the file name of `anonymous_file` and content type of `application/octet-stream`, so the recommended approach is to specify a custom content type with the `anthropic.File(reader io.Reader, filename string, contentType string)` helper, which wraps any `io.Reader` with the appropriate file name and content type.
559559
560560```go
561561// A file from the file system
from line 570
570570}
571571```
572572
573The file name and content type can also be customized by implementing `Name() string` or `ContentType() string` on the run-time type of `io.Reader`. Note that `os.File` implements `Name() string`, so a file returned by `os.Open` will be sent with the file name on disk.
573The file name and content type can also be customized by implementing `Name() string` or `ContentType() string` on the runtime type of `io.Reader`. Note that `os.File` implements `Name() string`, so a file returned by `os.Open` is sent with the file name on disk.
574574
575575## Pagination
576576
from line 592
592592}
593593```
594594
595Or you can use simple `.List()` methods to fetch a single page and receive a standard response object with additional helper methods like `.GetNextPage()`:
595Or you can use simple `.List()` methods to fetch a single page and receive a standard response object with additional helper methods such as `.GetNextPage()`:
596596
597597```go
598598page, err := client.Messages.Batches.List(context.TODO(), anthropic.MessageBatchListParams{
from line 627
627627)
628628```
629629
630The request option `option.WithDebugLog(nil)` may be helpful while debugging.
630The request option `option.WithDebugLog(nil)` might be helpful while debugging.
631631
632632See the [full list of request options](https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go/option).
633633
from line 692
692692
693693### Making custom/undocumented requests
694694
695This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, params, or response properties, the library can still be used.
695This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, parameters, or response properties, the library can still be used.
696696
697697#### Undocumented endpoints
698698
699To make requests to undocumented endpoints, you can use `client.Get`, `client.Post`, and other HTTP verbs. `RequestOptions` on the client, such as retries, will be respected when making these requests.
699To make requests to undocumented endpoints, you can use `client.Get`, `client.Post`, and other HTTP verbs. `RequestOptions` on the client, such as retries, are respected when making these requests.
700700
701701```go
702702var (
from line 714
714714}
715715```
716716
717#### Undocumented request params
717#### Undocumented request parameters
718718
719To make requests using undocumented parameters, you may use either the `option.WithQuerySet()` or the `option.WithJSONSet()` methods.
719To make requests using undocumented parameters, you can use either the `option.WithQuerySet()` or the `option.WithJSONSet()` functions.
720720
721721```go
722722params := FooNewParams{
from line 730
730730
731731#### Undocumented response properties
732732
733To access undocumented response properties, you may either access the raw JSON of the response as a string with `result.JSON.RawJSON()`, or get the raw JSON of a particular field on the result with `result.JSON.Foo.Raw()`.
733To access undocumented response properties, you can either access the raw JSON of the response as a string with `result.JSON.RawJSON()`, or get the raw JSON of a particular field on the result with `result.JSON.Foo.Raw()`.
734734
735735Any fields that are not present on the response struct are saved and can be accessed through `result.JSON.ExtraFields`, which is a `map[string]respjson.Field`.
736736
No line in this hunk matches that.