Skip to main content
MemLayer authenticates every request using an API key that you pass in the X-API-Key HTTP header. There are no OAuth flows or session tokens — every call your agent makes must include a valid key, and MemLayer will reject any request that is missing one or that supplies an incorrectly formatted value.

Get Your API Key

1

Visit memlayer.online

Open memlayer.online in your browser and click Sign Up.
2

Create your free account

Register with your email address. The free plan activates immediately — no credit card is required, and you receive 500 memories and 100 requests per day from the moment your account is confirmed.
3

Find your API key

After signing up, your API key is displayed in the dashboard under Settings → API Keys. A copy of it is also sent to the email address you registered with.
4

Note the key format

Your key always starts with the prefix ml_live_ followed by a random alphanumeric string — for example, ml_live_a1b2c3d4e5f6. MemLayer rejects keys that do not match this format with a 401 error.

Using Your API Key

Pass your key in the X-API-Key header on every request. The examples below show the three most common integration patterns.
Pass your key directly to MemLayerClient at initialisation time. The SDK attaches the X-API-Key header to every request automatically so you never have to manage headers yourself.
import os
from memlayer import MemLayerClient

client = MemLayerClient(
    api_key=os.environ.get("MEMLAYER_API_KEY"),
    base_url="https://memlayer.online"
)

# All subsequent calls are authenticated automatically
result = client.remember(
    "User is on the Pro plan",
    user_id="user_123",
    agent_id="billing_bot"
)
Use AsyncMemLayerClient with the same api_key argument for async agent frameworks.

Keeping Your Key Safe

Never commit your API key to version control. If your key is exposed in a public repository, anyone can make requests on your behalf and exhaust your quota. Rotate it immediately from the dashboard under Settings → API Keys if you suspect a leak.
Store your API key in an environment variable and read it at runtime. This keeps the key out of your source code and configuration files that might be checked in.
import os
from memlayer import MemLayerClient

# Read the key from the environment — never hard-code it
api_key = os.environ.get("MEMLAYER_API_KEY")

if not api_key:
    raise RuntimeError(
        "MEMLAYER_API_KEY environment variable is not set. "
        "Export it before running this script."
    )

client = MemLayerClient(api_key=api_key, base_url="https://memlayer.online")
For local development, use a .env file with a tool like python-dotenv and add .env to your .gitignore. For production deployments, inject the key through your hosting platform’s secrets manager (e.g., AWS Secrets Manager, Vercel Environment Variables, or Kubernetes Secrets).

Authentication Errors

If MemLayer cannot authenticate your request, it returns a JSON error response with one of the following status codes and messages.
HTTP StatusReasonResolution
401Invalid or missing API key — the X-API-Key header was absent or the key does not exist.Check that you are including the X-API-Key header and that the key value matches what is shown in your dashboard.
401Wrong key format — the key does not start with ml_live_.Make sure you copied the full key from the dashboard, including the ml_live_ prefix.
403Account suspended — your account has been flagged and access is restricted.Contact support@memlayer.online to resolve the suspension.
The Python SDK raises an AuthenticationError exception on any 401 response, so you can catch it explicitly in your agent’s error-handling logic without inspecting raw HTTP status codes.
from memlayer import MemLayerClient, AuthenticationError

try:
    client = MemLayerClient(api_key="ml_live_invalid", base_url="https://memlayer.online")
    client.remember("test", user_id="u1", agent_id="bot")
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
    # Re-prompt for a valid key or exit gracefully