Authentication
You'll need to authenticate your requests to access any of the endpoints in the Martian API. Authentication is done using API keys with bearer token authentication.
Getting Your API Key
- Sign up or log in to the Martian Dashboard
- Navigate to the API Keys section
- Create a new API key or copy an existing one
Using Your API Key
Bearer Token Authentication
The Martian API uses bearer token authentication. Include your API key in the Authorization
header of your requests:
curl https://api.withmartian.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MARTIAN_API_KEY" \
-d '{
"model": "openai/gpt-4.1-nano",
"messages": [
{
"role": "user",
"content": "Hello, world!"
}
]
}'
API Key Security
- Name
Keep it secret
- Description
Never commit your API key to version control or expose it in client-side code.
- Name
Use environment variables
- Description
Store your API key in environment variables or a secure secrets management system.
- Name
Rotate regularly
- Description
Rotate your API keys periodically and immediately if you suspect they've been compromised.
- Name
Monitor usage
- Description
Track your API usage in the Martian Dashboard to detect unauthorized access.
If you believe your API key has been compromised, immediately revoke it in the Martian Dashboard and generate a new one.
Using SDKs
When using official OpenAI or Anthropic SDKs, you only need to configure the base URL and API key. The SDKs handle authentication automatically:
OpenAI SDK Setup
import openai
client = openai.OpenAI(
base_url="https://api.withmartian.com/v1",
api_key=MARTIAN_API_KEY
)
Anthropic SDK Setup
import anthropic
client = anthropic.Anthropic(
base_url="https://api.withmartian.com/v1",
api_key=MARTIAN_API_KEY
)