{"modulePath":"github.com/braintrustdata/braintrust-sdk-go","version":"v0.20.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package https\n\nPackage https provides a unified HTTP client for making API requests with centralized auth, error handling, and debug logging.\n\n## Functions\n\n```go\nfunc CheckAndClose(resp *http.Response, err error) error\n```\nCheckAndClose closes a response whose body is not needed and rejects non-2xx statuses.\n\n```go\nfunc CheckResponse(resp *http.Response) error\n```\nCheckResponse returns an HTTPError for non-success status codes, consuming the error body. It leaves successful bodies untouched. The caller owns Body.Close. SDK loaders also use this with plain generated clients, whose transports need not reject non-2xx responses.\n\n```go\nfunc DecodeJSON[T any](resp *http.Response, err error) (T, error)\n```\nDecodeJSON closes a response, rejects non-2xx statuses, and decodes the successful body. Pass a generated operation's results directly:\n\n\trows, err := https.DecodeJSON[rowList](client.GetDataset(ctx, params))\n\n```go\nfunc NewGenerated(transport *Client) *openapi.Client\n```\nNewGenerated connects generated REST operations to the configured SDK transport. A nil transport returns nil.\n\n```go\nfunc Positive(value int) *int\n```\nPositive represents an optional positive query limit.\n\n```go\nfunc Query(name, value string) openapi.RequestEditorFn\n```\nQuery preserves a public query parameter missing from the pinned specification. Generated parameters are retained; an empty value is omitted.\n\n```go\nfunc String(value string) *string\n```\nString represents an optional nonempty query parameter.\n\n## Types\n\n```go\ntype Client struct {\n\t// contains filtered or unexported fields\n}\n```\nClient is a unified HTTP client for API requests.\n\n```go\nfunc NewClient(apiKey, baseURL string, log logger.Logger) *Client\n```\nNewClient creates a new HTTP client with the given credentials and base URL. The baseURL parameter is the base URL (e.g., \"[https://api.braintrust.dev](https://api.braintrust.dev)\" or \"[https://www.braintrust.dev](https://www.braintrust.dev)\").\n\n```go\nfunc NewWrappedClient(apiKey, baseURL string, httpClient *http.Client, log logger.Logger) *Client\n```\nNewWrappedClient creates a new HTTP client with a custom http.Client. This is useful for tests that need to wrap the HTTP client (e.g., with VCR).\n\n```go\nfunc (c *Client) APIKey() string\n```\nAPIKey returns the API key used by this client.\n\n```go\nfunc (c *Client) BaseURL() string\n```\nBaseURL returns the configured server URL, including any deployment prefix.\n\n```go\nfunc (c *Client) Client() *http.Client\n```\nClient returns the underlying http.Client. This is useful for extracting the client for auth.Session when using VCR.\n\n```go\nfunc (c *Client) Do(req *http.Request) (*http.Response, error)\n```\nDo executes the HTTP request with auth, error checking, and logging.\n\n```go\nfunc (c *Client) GET(ctx context.Context, path string, params map[string]string) (*http.Response, error)\n```\nGET makes a GET request with query parameters. The path is appended to the base URL (e.g., \"/v1/project\").\n\n```go\nfunc (c *Client) JSONBody(body any) (io.Reader, error)\n```\nJSONBody serializes a request body. Do logs it when the request is sent.\n\n```go\nfunc (c *Client) POST(ctx context.Context, path string, body interface{}) (*http.Response, error)\n```\nPOST makes a POST request with a JSON body. The path is appended to the base URL (e.g., \"/api/apikey/login\").\n\n```go\ntype HTTPError struct {\n\tStatusCode int\n\tBody       string\n\t// contains filtered or unexported fields\n}\n```\nHTTPError represents an HTTP error response with status code.\n\n```go\nfunc (e *HTTPError) Error() string\n```\n\n```go\nfunc (e *HTTPError) Unwrap() error\n```\n\n```go\ntype OpenAPIClient struct {\n\topenapi.Client\n\t// contains filtered or unexported fields\n}\n```\nOpenAPIClient uses generated endpoints while retaining SDK authentication, errors, timeouts, logging, and the caller's configured HTTP client.\n\n```go\nfunc NewOpenAPIClient(transport *Client) *OpenAPIClient\n```\nNewOpenAPIClient adapts an existing transport without changing its configuration. A nil transport stays nil so facade validation can run before any I/O.\n\n```go\nfunc (c *OpenAPIClient) Do(req *http.Request) (*http.Response, error)\n```\nDo sends generated requests unchanged through the shared SDK transport.\n\n```go\nfunc (c *OpenAPIClient) JSONBody(value any) (io.Reader, error)\n```\nJSONBody preserves public request models and arbitrary JSON without converting through generated models. Generated WithBody methods accept the encoded body.\n\n","path":"github.com/braintrustdata/braintrust-sdk-go/internal/https","name":"https","synopsis":"Package https provides a unified HTTP client for making API requests with centralized auth, error handling, and debug logging.","isRedistributable":true}
