> ## 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.
</Warning>

### Using API Keys

Include the API key in the `Authorization` header:

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

### Example Request

<RequestExample>
  ```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()
  ```
</RequestExample>

### Response

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "success": true,
    "data": {
      "id": "ws_abc123",
      "name": "My Workspace",
      "description": "Research workspace"
    }
  }
  ```

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

## 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

<AccordionGroup>
  <Accordion title="Secure Storage">
    * Store API keys in environment variables
    * Never commit keys to version control
    * Use secrets management services
    * Rotate keys periodically
  </Accordion>

  <Accordion title="Key Management">
    * Create separate keys per environment
    * Use descriptive names for keys
    * Delete unused keys promptly
    * Monitor key usage
  </Accordion>

  <Accordion title="Request Security">
    * Always use HTTPS
    * Don't log API keys
    * Implement request timeouts
    * Handle errors gracefully
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Core Memory Operations" icon="brain" href="/features/memorylake/api-reference/core-memory/overview">
    Start with the core APIs
  </Card>

  <Card title="Error Handling" icon="triangle-exclamation" href="/features/memorylake/api-reference/errors">
    Handle API errors
  </Card>
</CardGroup>
