Authentication
Learn how to authenticate your requests to the Sematryx API using API keys.
API Key Authentication
Sematryx uses API keys for authentication. Include your API key in the Authorization header of every request using the Bearer token format.
Authentication with curl
curl -X POST https://api.sematryx.com/v1/optimize \
-H "Authorization: Bearer aeao_1234567890abcdef" \
-H "Content-Type: application/json" \
-d '{
"objective_function_id": "func_1234567890",
"bounds": [[-5, 5], [-5, 5]]
}'Getting Your API Key
You can get your API key by:
- Visiting the API Keys page
- Selecting a pricing plan
- Completing the checkout process
- Your API key will be displayed on the success page
Using SDKs
When using our official SDKs, authentication is handled automatically:
Authentication with JavaScript SDK
import { Sematryx } from '@sematryx/javascript-sdk'
// Initialize with your API key
const sematryx = new Sematryx('sematryx_1234567890abcdef')
// All requests will automatically include authentication
const result = await aeao.optimize({
objective_function: (x) => x.reduce((s, v) => s + v * v, 0),
bounds: [[-5, 5], [-5, 5]],
max_evaluations: 1000
})Security Best Practices
Keep Your API Key Secure
- • Never expose your API key in client-side code
- • Store API keys as environment variables
- • Rotate your API keys regularly
- • Use different keys for development and production
- • Monitor your API key usage from the dashboard
Error Responses
If authentication fails, you'll receive a 401 Unauthorized response:
Authentication error response
{
"error": {
"type": "authentication_error",
"message": "Invalid API key provided",
"code": "invalid_api_key"
}
}