Skip to content

Configuration

Igor Sazonov edited this page Jul 14, 2026 · 1 revision

The client is configured entirely through functional options passed to nansen.New. Every option is optional; the table below lists the defaults that apply when an option is omitted.

Available Options

Option Signature Default Description
WithBaseURL WithBaseURL(url string) Option https://api.nansen.ai Overrides the API base URL. Useful for testing against a staging environment.
WithHTTPClient WithHTTPClient(client *http.Client) Option &http.Client{Timeout: 30s} Replaces the default HTTP client. Use this to configure proxies, custom TLS settings, or a shared transport.
WithTimeout WithTimeout(timeout time.Duration) Option 30s Sets a fallback request timeout. This timeout is applied only when the context passed to a service method does not already carry a deadline.
WithRetry WithRetry(maxAttempts int, initialDelay, maxDelay time.Duration) Option Disabled Enables automatic retries with exponential backoff. maxAttempts is the maximum number of additional attempts after the first failure.

Full Example

client, err := nansen.New(apiKey,
    nansen.WithBaseURL("https://api.nansen.ai"),
    nansen.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}),
    nansen.WithTimeout(30 * time.Second),
    nansen.WithRetry(3, 500*time.Millisecond, 5*time.Second),
)

Validation

nansen.New validates each option as it is applied. It returns an error if:

  • The API key is an empty string.
  • WithBaseURL is called with an empty string.
  • WithHTTPClient is called with a nil pointer.
  • WithTimeout is called with a non-positive duration.
  • WithRetry is called with a negative maxAttempts, or with a non-positive initialDelay or maxDelay when maxAttempts > 0.

Timeout Interaction with Retries

When WithRetry is active, the timeout budget set by WithTimeout (or by a deadline on the context) covers all retry attempts together, not each one individually. This means the total time spent across all attempts — including backoff sleep — will never exceed the deadline you specified.

Concurrency

The *Client value returned by nansen.New is safe to use concurrently from multiple goroutines. You should create one client per application and share it freely.

Clone this wiki locally