Repository navigation
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.
| 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. |
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),
)nansen.New validates each option as it is applied. It returns an error if:
- The API key is an empty string.
-
WithBaseURLis called with an empty string. -
WithHTTPClientis called with anilpointer. -
WithTimeoutis called with a non-positive duration. -
WithRetryis called with a negativemaxAttempts, or with a non-positiveinitialDelayormaxDelaywhenmaxAttempts > 0.
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.
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.