Documentation Cloud4.ai
HomeCloud ConsoleDiscord Community
  • 🌟Cloud4.ai Documentation
  • Introduction
    • Overview
    • Security
    • 💸Pricing
    • 😀Commission to Model Developers
    • Backlog
    • Enterprise
  • SDK
    • 🚩Quick Start
    • 🔐Authentication
    • ⚙️Configurations & Env Variables
    • ⭐Request
      • Execution Options
      • Execution Schedule
    • 🔗Response
    • 🔶Commands
    • 🟥Errors
  • Concept
    • Organization Structure
    • C4AI Command
    • SIC (Service Identity Code)
    • .cc4
    • 📕Glossary
  • Services
    • General Information
    • 🟨EES (Elastic Endpoint)
      • 🔶EES Commands
      • Use Cases
    • 🟨CSS Credentials Store
      • Best Practices
    • 🟨AAC (AI API Connector)
      • AAC Commands
    • 🟨AIL (AI Lambda)
    • 🟨CES (Chain Execution)
    • 🟨API Schema
    • 🟨KDB (Knowledgebase)
      • KDB Commands
    • 🟨CDB (Context Data Storage)
    • 🟨PL (Prompt Library)
      • PL Commands
    • 🟨PLPrompt (Prompt)
      • Prompt Commands
    • 🟨IDR (Intellectual Data Retrieval)
    • 🟨IDTS (Intellectual Data Transformation Service)
    • 🟨IDOS (Intellectual Data Observation Service)
    • 🟨Files
    • 🟨SJS (Scheduled Job Service )
Powered by GitBook
On this page
  • Introduction
  • Priority
  • Direct Credentials
  • Config File
  • Environment Variables

Was this helpful?

  1. SDK

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:

import { C4AI_SDK_Context } from "@c4ai-sdk/global/C4AISDKContext.class";

C4AI_SDK_Context.setCredentials(
    "C4AI--client::769e...YOUR_CREDS....04bc161",
    "C4AI--secret::5ca62...YOUR_CREDS....99249dab36bf4db"
);

/**
 * Not mandatory in real requests. 
 * Will authenticate automatically during request
 */
await C4AI_SDK_Context.authenticate();

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:

# Create the c4ai.conf.json file
touch c4ai.conf.json
// Edit c4ai.conf.json and set credentials
{
    "client_id": "YOUR_CLIENT_ID", // mandatory
    "client_secret": "YOUR_CLIENT_SECRET" // mandatory
}

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:

# Create the .env file
touch .env
# Add mandatory variables to .env
C4AI_CLIENT_ID=C4AI--client::769e...YOUR_CREDS....04bc161
C4AI_CLIENT_SECRET=C4AI--secret::5ca62...YOUR_CREDS....99249dab36bf4db

Then authenticate:

import { config } from 'dotenv';
config(); // just for example
import { C4AI_SDK_Context } from "@c4ai-sdk/global/C4AISDKContext.class";

/**
 * Not mandatory in real requests. 
 * Will authenticate automatically during request
 */
await C4AI_SDK_Context.authenticate(); 

Note: Do not forget to include the .env file in .gitignore to prevent credentials from being pushed to the repository.

PreviousQuick StartNextConfigurations & Env Variables

Last updated 1 year ago

Was this helpful?

Note: Read more in the section.

🔐
C4AI Config File