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.
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
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
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
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
# 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 ~/.bashrcWindows
# 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:
LEMMA_API_KEY=your_api_key_hereImportant
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:
{
"error": {
"message": "Invalid API key provided",
"type": "authentication_error",
"code": "invalid_api_key"
}
}Next Steps
Now that you know how to authenticate, explore our API endpoints to start building.
Explore API Reference