Skip to main content

client.go (package eai)

Source: sdks/go/client.go. Back to the Go SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Model Client​

Client is safe for concurrent use.

This model declares no field.

Client.BaseURL​

BaseURL() string

BaseURL returns the configured base URL.

This element takes no parameter.

Returns: string. Base URL of the Control Plane set with WithBaseURL, without trailing slash.

Client.Locale​

Locale() string

Locale returns "en" or "fr".

This element takes no parameter.

Returns: string. Message language of the client, en or fr.

Client.Tenant​

Tenant() string

Tenant returns the configured tenant slug.

This element takes no parameter.

Returns: string. Tenant slug set with WithTenant, empty when none was given.

Type alias Option​

Option configures a Client.

Definition: func(*Client) error.

Functions​

WithBaseURL​

WithBaseURL(u string) Option

WithBaseURL sets the Control Plane URL (without /v1). Required.

NameTypeDefaultRequiredDescription
ustringyesControl Plane URL without /v1; trailing slashes are removed.

Returns: Option. An Option to pass to NewClient.

WithAPIKey​

WithAPIKey(k string) Option

WithAPIKey sets the tenant API key sent as X-API-Key.

NameTypeDefaultRequiredDescription
kstringyesTenant API key, sent as X-API-Key on every request.

Returns: Option. An Option to pass to NewClient.

WithToken​

WithToken(t string) Option

WithToken sets an OIDC access token sent as Authorization: Bearer.

NameTypeDefaultRequiredDescription
tstringyesOIDC access token, sent as Authorization: Bearer <t>.

Returns: Option. An Option to pass to NewClient.

WithTenant​

WithTenant(t string) Option

WithTenant sets the tenant slug. The server resolves the tenant from the credential; without any credential the slug is sent as X-Dev-Tenant (development mode, EAI_AUTH_DEV=1).

NameTypeDefaultRequiredDescription
tstringyesTenant slug, sent as X-Dev-Tenant only when no API key nor token is set.

Returns: Option. An Option to pass to NewClient.

WithProject​

WithProject(p string) Option

WithProject sets X-Project.

NameTypeDefaultRequiredDescription
pstringyesProject sent as X-Project on every request.

Returns: Option. An Option to pass to NewClient.

WithEnvironment​

WithEnvironment(e string) Option

WithEnvironment sets X-Environment (dev, test, staging, prod).

NameTypeDefaultRequiredDescription
estringyesEnvironment sent as X-Environment: dev, test, staging or prod.

Returns: Option. An Option to pass to NewClient.

WithLocale​

WithLocale(l string) Option

WithLocale selects the message language, "en" (default) or "fr"; sent as Accept-Language.

NameTypeDefaultRequiredDescription
lstringyesLanguage code; any value starting with fr selects French, anything else English.

Returns: Option. An Option to pass to NewClient.

WithRetries​

WithRetries(n int) Option

WithRetries sets how many times network errors and HTTP 408/429/502/503/504 are retried (default 2).

NameTypeDefaultRequiredDescription
nintyesNumber of retries, 0 or more; a negative value makes NewClient fail.

Returns: Option. An Option to pass to NewClient.

WithRetryBaseDelay​

WithRetryBaseDelay(d time.Duration) Option

WithRetryBaseDelay sets the first backoff delay, doubled at each attempt; Retry-After wins when present.

NameTypeDefaultRequiredDescription
dtime.DurationyesDelay before the first retry (250 ms by default).

Returns: Option. An Option to pass to NewClient.

WithHTTPClient​

WithHTTPClient(h *http.Client) Option

WithHTTPClient sets a custom *http.Client (timeouts, proxy, TLS, mTLS).

NameTypeDefaultRequiredDescription
h*http.ClientyesHTTP client used for every request instead of the default one (60 second timeout).

Returns: Option. An Option to pass to NewClient.

WithHeader​

WithHeader(name string, value string) Option

WithHeader adds a header sent on every request.

NameTypeDefaultRequiredDescription
namestringyesName of the HTTP header to send on every request.
valuestringyesValue of the header; a later WithHeader with the same name replaces it.

Returns: Option. An Option to pass to NewClient.

WithTraceparent​

WithTraceparent(f func() string) Option

WithTraceparent sets a function returning the W3C traceparent of the current span; a random one is generated per request otherwise (a per call WithCallTraceparent wins).

NameTypeDefaultRequiredDescription
ffunc() stringyesFunction called for each request that returns the W3C traceparent header value.

Returns: Option. An Option to pass to NewClient.

NewClient​

NewClient(opts ...Option) (*Client, error)

NewClient builds a client.

NameTypeDefaultRequiredDescription
opts...OptionnoPer call options (query, idempotency key, traceparent, headers).

Returns: (*Client, error). The configured *Client of the Control Plane API, its services ready. The error is set when an option fails, the base URL is missing or the TLS settings are invalid, nil on success.

Raises: error.