> This page is for version v8.3.0 (default).
> For other versions, use one of these documentation indexes:
> - v8.3.0 (default): https://docs.workflows.com/v-8-3-0/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.workflows.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.workflows.com/_mcp/server.

# Authentication

> How to authenticate the MindSim SDK in different environments.

# 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:
   ```bash
   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:

```typescript
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.

```bash
export MINDSIM_API_KEY="ms_sk_..."
```

```typescript
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.

```typescript
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.`