🔐Authentication
Introduction
C4AI SDK provides several ways to pass credentials and configurations:
Directly through context
Using the C4AI Config File
Using Environment Variables
Each case may be useful for specific scenarios depending on your application architecture.
Priority
In some cases, it's possible to combine several approaches to SDK configuration. For these scenarios, the priority of configurations should be taken into account. The standard priority is the same as above
Direct -> c4ai.conf.json
-> Env Variables
Direct Credentials
This approach has the highest priority, and other credentials will be overwritten by the provided ones.
Example:
Config File
Another way to pass credentials and configurations is via the c4ai.conf.json
file.
In case credentials have not been passed directly, the SDK will use credentials from the file in the project root folder.
Example:
Then authentication will be done automatically during the request execution.
Environment Variables
This is the most secure and recommended way to pass your credentials to the SDK. However, it will only be used if the configuration file c4ai.conf.json
and direct credentials have not been provided.
Example:
Then authenticate:
Note: Do not forget to include the
.env
file in.gitignore
to prevent credentials from being pushed to the repository.
Last updated