Getting started

Authentication

The Lemma API uses API keys to authenticate requests. You can view and manage your API keys in the Lemma Console.

API Keys

Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

All API requests should include your API key in an x-api-key HTTP header as follows:

HTTP Header
x-api-key: LEMMA_API_KEY

Keep your API keys secure

Your secret API keys should only be used on the server-side. Never expose them in client-side code, mobile apps, or version control systems.

Making Authenticated Requests

Here's how to authenticate your requests using different methods:

Using cURL

Bash
curl https://api.lemma.la/v1/search \
  -H "Content-Type: application/json" \
  -H "x-api-key: $LEMMA_API_KEY" \
  -d '{
    "question": "warfarin interactions"
  }'

Using Python

Python
import os
import requests

api_key = os.environ.get("LEMMA_API_KEY")

response = requests.post(
    "https://api.lemma.la/v1/search",
    headers={
        "Content-Type": "application/json",
        "x-api-key": api_key
    },
    json={
        "question": "warfarin interactions"
    }
)

data = response.json()
print(data)

Using JavaScript

JavaScript
const apiKey = process.env.LEMMA_API_KEY;

const response = await fetch("https://api.lemma.la/v1/search", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": apiKey
  },
  body: JSON.stringify({
    question: "warfarin interactions"
  })
});

const data = await response.json();
console.log(data);

Using Environment Variables

We recommend storing your API key in an environment variable to keep it secure and make it easy to manage across different environments.

Linux/macOS

Bash
# Temporary (current session only)
export LEMMA_API_KEY="your_api_key_here"

# Permanent (add to ~/.bashrc or ~/.zshrc)
echo 'export LEMMA_API_KEY="your_api_key_here"' >> ~/.bashrc
source ~/.bashrc

Windows

PowerShell
# Temporary (current session only)
$env:LEMMA_API_KEY = "your_api_key_here"

# Permanent
[System.Environment]::SetEnvironmentVariable('LEMMA_API_KEY', 'your_api_key_here', 'User')

Using .env Files

For development, you can create a .env file in your project root:

.env
LEMMA_API_KEY=your_api_key_here

Important

Never commit your .env file to version control. Add it to your .gitignore file.

Authentication Errors

If authentication fails, you'll receive an error response:

401 Unauthorized
{
  "error": {
    "message": "Invalid API key provided",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}
401

Unauthorized

Your API key is missing, invalid, or has been revoked.

403

Forbidden

Your API key doesn't have permission to access this resource.

429

Rate Limit Exceeded

You've exceeded your rate limit. Wait before making more requests.

Next Steps

Now that you know how to authenticate, explore our API endpoints to start building.

Explore API Reference