API Key Management
Choose what each API key can do and where it can be used from.
Each API key has permission scopes, which decide what it can do, and an optional
IP allowlist, which decides where it can be used from. Set both per key on the
website, or through the API with an api_key_manager key. Give each key only what
it needs, so a leaked key can do less harm.
Permission scopes
| Permission scope | What the key can do |
|---|---|
regular | Everything in the REST API: generate images, video and audio, upload inputs, check and cancel tasks, download and share results, manage custom LoRAs, live sessions and projects, use the MCP server and the batch API, and read your account, such as models, balance, usage and history. |
api_key_manager | List, create and revoke API keys, and change a key's scopes or IP allowlist. |
A key can hold both scopes. New keys get regular unless you choose otherwise.
Changing your account is only available on the website, whatever scopes a key has: adding funds, auto-reload, organization settings, and deleting history.
IP allowlist
An IP allowlist limits where an API key can be used. Each key has its own list. An empty list allows requests from any IP address.
You can add up to 100 IPv4 or IPv6 addresses or CIDR networks. Use the public outbound IP of the server that calls MachGen. If it uses a proxy or NAT, use that service's public outbound IP. Example addresses below are placeholders; replace them with your own.
Set them on the website
- Open Profile -> API Keys.
- Permission scopes: pick them when you create a key. To change them later, click the pencil button in the key's Permission scopes column, tick the scopes you want, then click Save.
- IP allowlist: in the key's IP allowlist column, click + to add an address or network. Edit the inputs or use the trash icon to remove entries, then click Save. To allow any IP again, remove every entry and save.
Changes apply to the next request. Requests from an IP outside the list receive
403 Forbidden.
Manage keys with the API
api_key_manager keys only
Only a key with the api_key_manager scope can call the API key endpoints. It can only give a key the scopes it has
itself, so a key with only api_key_manager cannot create a key that generates.
Copy a key's ID from the API Keys page, or find it with GET /api/v0/api-keys.
The list response includes each key's scopes and ip_allowlist.
Create a key
curl --request POST https://api.machgen.ai/api/v0/api-keys \
--header "Authorization: Bearer ${MACHGEN_API_KEY_MANAGER_KEY}" \
--header "Content-Type: application/json" \
--data '{"name": "deploy-bot", "scopes": ["api_key_manager"]}'Change a key's scopes
Send the full list of scopes the key should have:
curl --request PUT "https://api.machgen.ai/api/v0/api-keys/${KEY_ID}/scopes" \
--header "Authorization: Bearer ${MACHGEN_API_KEY_MANAGER_KEY}" \
--header "Content-Type: application/json" \
--data '{"scopes": ["api_key_manager"]}'Update the IP allowlist
PUT /api/v0/api-keys/{key_id}/ip-allowlist replaces the entire list. To add an
IP, include both the existing entries you want to keep and the new entry. You can
only update active keys that belong to your account.
curl --request PUT \
"https://api.machgen.ai/api/v0/api-keys/${KEY_ID}/ip-allowlist" \
--header "Authorization: Bearer ${MACHGEN_API_KEY_MANAGER_KEY}" \
--header "Content-Type: application/json" \
--data '{
"ip_allowlist": [
"203.0.113.10",
"198.51.100.0/24",
"2001:db8::/32"
]
}'The response contains the key's details and saved ip_allowlist. Duplicate
entries are removed and networks are returned in their canonical form. To remove
all IP restrictions, send {"ip_allowlist": []}.
If the key you authenticate with is the key being updated, your current IP must be allowed by its existing list. You do not send the allowlist with each request.
Fix a refused request
If your IP changes or you save the wrong address, sign in to the website and correct the list on the API Keys page. A key's restrictions never stop you from editing it in your signed-in browser.
| Status | What to check |
|---|---|
401 Unauthorized | The API key is missing, invalid, or revoked. |
403 Forbidden with This API key needs the ... scope | The key doesn't have a scope this request needs. Add it on the API Keys page. |
403 Forbidden with This endpoint isn't available with an API key. | The request is only available on the website. |
403 Forbidden with An API key can only grant scopes it has | The key tried to give another key a scope it doesn't have itself. |
403 Forbidden with Source IP is not allowed for this API key | The calling server's public outbound IP is outside the authenticating key's list. |
404 Not Found with Active API key not found | The key being edited does not exist, is revoked, or belongs to another account. |
422 Unprocessable Entity | An entry is not a valid IP address or network, or the list exceeds 100 entries. The saved list is unchanged. |