Skip to main content
AmikaClient needs a credential for every request. Provide exactly one of three options:
  • apiKey: a static Amika API key. This is the usual choice.
  • accessToken: a static bearer token.
  • tokenSource: an object the client calls each time it needs a token.

Static key

The simplest case: pass a key string you already have.
Static credentials must be non-empty strings, or the constructor throws.

The TokenSource interface

For tokens that need to be fetched or refreshed, implement TokenSource:
The client calls token() for every request. Returning a promise lets you fetch or refresh on demand.

A refreshing token source

The client awaits token() on each request, so you can cache and refresh inside it.
fetchTokenFromYourAuthService stands in for your own credential-loading code.
The SDK never reads AMIKA_API_KEY from the environment or disk on your behalf. Sourcing the credential, from an env var, a secret manager, or an auth service, is always the caller’s responsibility.