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 auth tokens), how to configure your client, and some basic information about error handling and production readiness.

Constructing a Topics client
The TopicClient
is the main object you will use in your code to interact with Momento services. To instantiate one, you need to pass a CredentialProvider
, a Configuration
, and a default time to live (TTL) value. The default TTL determines how long items using that CacheClient
will be stored in the cache before the cache deletes them.
Here is an example of how to construct a TopicClient
:
- JavaScript
- Python
- Go
- C#
new TopicClient({
configuration: TopicConfigurations.Default.latest(),
credentialProvider: CredentialProvider.fromEnvironmentVariable({
environmentVariableName: 'MOMENTO_API_KEY',
}),
});
topic_client = TopicClientAsync(
TopicConfigurations.Default.latest(),
CredentialProvider.from_environment_variable("MOMENTO_AUTH_TOKEN")
)
credProvider, err := auth.NewEnvMomentoTokenProvider("MOMENTO_API_KEY")
if err != nil {
panic(err)
}
topicClient, err := momento.NewTopicClient(
config.TopicsDefault(),
credProvider,
)
if err != nil {
panic(err)
}
new TopicClient(
TopicConfigurations.Laptop.latest(),
new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")
);
Instantiating credential providers using Momento auth tokens
You need to provide a Momento auth token 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:
- JavaScript
- Python
- Java
- PHP
- Elixir
CredentialProvider.fromEnvironmentVariable({environmentVariableName: 'MOMENTO_API_KEY'});
CredentialProvider.from_environment_variable("MOMENTO_AUTH_TOKEN")
CredentialProvider.fromEnvVar("MOMENTO_AUTH_TOKEN");
CredentialProvider::fromEnvironmentVariable("MOMENTO_AUTH_TOKEN");
Momento.Auth.CredentialProvider.from_env_var!("MOMENTO_AUTH_TOKEN")
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:
- JavaScript
- Java
- Elixir
const apiKey = retrieveApiKeyFromYourSecretsManager();
CredentialProvider.fromString({apiKey: apiKey});
final String authToken = retrieveAuthTokenFromYourSecretsManager();
CredentialProvider.fromString(authToken);
auth_token = retrieve_auth_token_from_your_secrets_manager()
Momento.Auth.CredentialProvider.from_string!(auth_token)
For an example of how to retrieve credentials from AWS Secrets Manager, see Retrieving a Momento auth token from AWS Secrets Manager.
For general information on Momento authentication, see our auth page.
For more information, see our Response Objects page, and the docs for the specific SDK that you are using (under Develop
->SDKs
in the left nav).