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:
1import { MindSim } from "mindsim";
2
3// The SDK automatically loads credentials from the local config file
4const 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_..."
1import { MindSim } from "mindsim";
2
3// The SDK automatically detects process.env.MINDSIM_API_KEY
4const 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.

1import { MindSim } from "mindsim";
2import { getSecret } from "./my-secrets-manager";
3
4const startApp = async () => {
5 const apiKey = await getSecret("mindsim-prod-key");
6
7 const mindsim = new MindSim(apiKey);
8};

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.