api supports API authentication through an .auth() method:

const petstore = require('@api/petstore');

petstore.listPets().then(({ data }) => {
  // authenticated response

With the exception of OpenID and Mutual TLS it supports all forms of authentication supported by the OpenAPI specification! Supply .auth() with your auth credentials and it'll magically figure out how to use it according to the API you're using. 🧙‍♀️

For example:

  • HTTP Basic auth: sdk.auth('username', 'password')
  • Bearer tokens (HTTP or OAuth 2): sdk.auth('myBearerToken')
  • API Keys: sdk.auth('myApiKey')


The .auth() method is not chainable.