Skip to main content

Developing applications with Momento SDKs

Welcome! This page provides information about common constructs you will need in order to assemble Momento clients in all of our SDKs. This page covers how to provide your Momento credentials (called API keys), how to configure your client, and some basic information about error handling and production readiness.

Constructing a Storage Client

The StorageClient is the main object you will use in your code to interact with Momento services. To instantiate one, you need to pass a CredentialProvider and a Configuration.

Here is an example of how to construct a StorageClient:

return new PreviewStorageClient({
configuration: StorageConfigurations.Laptop.latest(),
credentialProvider: CredentialProvider.fromEnvironmentVariable('MOMENTO_API_KEY'),
});
info
Full example code and imports can be found here

Instantiating credential providers using Momento API keys

You need to provide a Momento API key when instantiating a Momento client. If you don't have one yet, you can get one from the Momento Web Console. Once you have a token, provide it to Momento SDKs when you create an instance of CredentialProvider. There are convenient factory methods provided to construct a CredentialProvider object, either from an environment variable or from a String. Below is an example of how to instantiate CredentialProvider from an environment variable:

CredentialProvider.fromEnvironmentVariable('MOMENTO_API_KEY');
info
Full example code and imports can be found here

If you're storing your Momento auth token in a secret manager such as AWS Secret Manager, GCP Secret Manager, or a local config file, you must first retrieve the credentials from there and then instantiate a CredentialProvider from a string, like this:

const apiKey = retrieveApiKeyFromYourSecretsManager();
CredentialProvider.fromString({apiKey: apiKey});
info
Full example code and imports can be found here

For an example of how to retrieve credentials from AWS Secrets Manager, see Retrieving a Momento auth token from AWS Secrets Manager.

For more information, see our API Reference page, and the docs for the specific SDK that you are using.