> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memorylake.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# API Authentication

> Authenticate your API requests to MemoryLake services

## Authentication

All API requests require an API key passed via the `Authorization` header.

### Obtaining an API Key

1. Navigate to a project in the MemoryLake console
2. Go to the **API Keys** tab
3. Click **"Create API Key"**
4. Copy the generated secret (format: `sk_xxxxxx`)

> [!WARNING]
>
> The API key secret is shown only once at creation. Store it securely — it cannot be retrieved again.

### What a Key Can Do

A key is bound to exactly one team — the team it was created under. Nothing in a request can change that: there is no team parameter, and no header overrides it. If you belong to several teams, you hold one key per team, and you govern a team with that team's key.

Within its team, a key acts with its creator's role. This matters most for [team, member and access-control endpoints](https://docs.memorylake.ai/features/memorylake/api-reference/team/get-team.md), which are authorized against what that person may do in the console — a member's key reads the team roster, an owner's key can also change it. If the creator loses a permission or leaves the team, their keys lose it too. A key that authenticates but lacks the required permission gets `403` with `ACCESS_DENIED`.

> [!NOTE]
>
> For automation that only needs to read, prefer a key created by a low-privilege member — or one issued for a [virtual member](https://docs.memorylake.ai/features/memorylake/api-reference/members/create-member.md). That is the cleanest way to limit what a leaked key can do.

### Using API Keys

Include the API key in the `Authorization` header:

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

### Example Request

```bash cURL theme={null}
curl -X GET 'https://app.memorylake.ai/openapi/memorylake/api/v3/workspaces/ws_abc123' \
  -H 'Authorization: Bearer sk_xxxxxx' \
  -H 'Content-Type: application/json'
```

```javascript Node.js theme={null}
const response = await fetch(
  'https://app.memorylake.ai/openapi/memorylake/api/v3/workspaces/ws_abc123',
  {
    headers: {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json'
    }
  }
);

const data = await response.json();
```

```python Python theme={null}
import requests

headers = {
    'Authorization': f'Bearer {api_key}',
    'Content-Type': 'application/json'
}

response = requests.get(
    'https://app.memorylake.ai/openapi/memorylake/api/v3/workspaces/ws_abc123',
    headers=headers
)

data = response.json()
```

### Response

```json Success (200) theme={null}
{
  "success": true,
  "data": {
    "id": "ws-8001856949ad4f6a5b6226f415ffa877",
    "name": "My Workspace",
    "description": "Research workspace"
  }
}
```

```json Error (401) theme={null}
{
  "success": false,
  "message": "Invalid or missing API key",
  "error_code": "UNAUTHORIZED"
}
```

## Error Responses

### 401 Unauthorized

Returned when the API key is missing or invalid:

```json theme={null}
{
  "success": false,
  "message": "Unauthorized access",
  "error_code": "UNAUTHORIZED"
}
```

**Solutions**:

* Verify API key is included in Authorization header
* Check header format: `Bearer YOUR_KEY`
* Ensure key hasn't been deleted
* Generate new key if lost

### 403 Forbidden

Returned when authentication is valid but the API key lacks sufficient permissions:

```json theme={null}
{
  "success": false,
  "message": "Access denied to this resource",
  "error_code": "FORBIDDEN"
}
```

**Solutions**:

* Verify project ID is correct
* Check API key is for the correct project
* Ensure resource exists

## Security Best Practices

> [accordion] Secure Storage
>
> * Store API keys in environment variables
> * Never commit keys to version control
> * Use secrets management services
> * Rotate keys periodically

> [accordion] Key Management
>
> * Create separate keys per environment
> * Use descriptive names for keys
> * Delete unused keys promptly
> * Monitor key usage

> [accordion] Request Security
>
> * Always use HTTPS
> * Don't log API keys
> * Implement request timeouts
> * Handle errors gracefully

## Next Steps

> [card] [Core Memory Operations](https://docs.memorylake.ai/features/memorylake/api-reference/core-memory/overview.md)
>
> Start with the core APIs

> [card] [Error Handling](https://docs.memorylake.ai/features/memorylake/api-reference/errors.md)
>
> Handle API errors


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.