Skip to navigation

Authentication

Authentication

The MindSim client requires a valid API Key to make requests. The SDK supports three authentication strategies designed for different environments.

1. Local Development (CLI)

Best for: Local prototyping, exploration, and individual development.

The SDK comes with a CLI tool that handles OAuth authentication via your browser.

  1. Run the authentication command in your terminal:
    mindsim auth
  2. A browser window will open. Log in with your MindSim credentials.
  3. Once successful, the API key is stored locally in ~/.mindsim/config.
  4. Initialize the SDK without arguments:
import { MindSim } from "mindsim";
// The SDK automatically loads credentials from the local config file
const mindsim = new MindSim();

2. Environment Variables

Best for: CI/CD pipelines, Docker containers, and production deployments.

The SDK looks for the MINDSIM_API_KEY environment variable. This takes precedence over local configuration files.

export MINDSIM_API_KEY="ms_sk_..."
import { MindSim } from "mindsim";
// The SDK automatically detects process.env.MINDSIM_API_KEY
const mindsim = new MindSim();

3. Constructor Injection

Best for: Applications using secret managers (AWS Secrets Manager, Vault) where keys are retrieved at runtime.

You can pass the API key directly as the first argument to the constructor.

import { MindSim } from "mindsim";
import { getSecret } from "./my-secrets-manager";
const startApp = async () => {
const apiKey = await getSecret("mindsim-prod-key");
const mindsim = new MindSim(apiKey);
};

Troubleshooting

If the SDK cannot find an API key in the environment variables, the local config file, or the constructor arguments, it will throw an error:

Error: API Key not found. Please run mindsim auth or pass the key to the constructor.