Once a serverless endpoint works, four settings keep it safe in daily use: a rate limit so one busy client cannot flood it, priorities so urgent jobs go first, lifetimes so old jobs do not wait for ever, and an automatic rollback so a broken update undoes itself. You need an endpoint and the apidly command (see Use the CLI and API from scratch). Changing endpoint settings needs a key with Full access; sending jobs needs Servers.
1. Set a rate limit
An endpoint takes at most 1,200 requests per minute through its address, all keys together, and one key at most 600. You can set a lower limit for one endpoint:
- Open Endpoints and select the endpoint.
- In Scaling settings, enter Requests per minute, for example
300. Leave it empty for the platform limit of 1,200. - Select Save.
The same from a terminal:
apidly endpoints update EPN_ID --rate-limit 300
apidly endpoints update EPN_ID --rate-limit noneThe second line goes back to the platform limit. Through the API:
curl -X PATCH https://apidly.com/api/v1/endpoints/EPN_ID \
-H "Authorization: Bearer $APIDLY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"rateLimitPerMinute": 300}'Send null to remove it. A request over the limit gets 429 with the code rate_limited and a Retry-After header, and it never reaches a worker, so it costs nothing. With your own limit set, every answer also carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. The limit can only lower the platform limit, and it does not apply to async jobs, which have their own limit of 100 waiting jobs. See Rate limits.
2. Put urgent jobs first with priorities
Async jobs wait in a queue until a worker is free. Each job can have a priority from -10 to 10; the default is 0. Waiting jobs of one endpoint go to workers with the highest priority first, and jobs of the same priority oldest first.
apidly endpoints submit EPN_ID /generate -d '{"prompt": "Answer this customer now"}' --priority 5
apidly endpoints submit EPN_ID /generate -d '{"prompt": "Nightly report"}' --priority=-5Write a negative value with =, as in the second line. Through the API:
curl -X POST https://apidly.com/api/v1/endpoints/EPN_ID/jobs \
-H "Authorization: Bearer $APIDLY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"path": "/generate", "input": {"prompt": "Nightly report"}, "priority": -5}'The order is strict, and this is the rule to plan for: a lower-priority job waits as long as a higher one is waiting for a worker. When there is always higher-priority work, it can wait until its queue time ends and then expire with no_worker. A higher-priority job that cannot be sent for a reason of its own (it failed, or another run already took it) does not hold the lower ones back. Give background work a negative priority rather than urgent work a high one, so that ordinary jobs at 0 are not held back. A job sent while a worker is free can start at once, unless a job with a higher priority is waiting. Jobs of different endpoints never affect each other.
3. Set how long jobs live
Two lifetimes can only shorten the defaults:
| Field | CLI flag | Range | Default | What it does |
|---|---|---|---|---|
queueTtlSeconds |
--queue-ttl |
60 to 3,600 | 3,600 | How long a job may wait for a worker. After that its status is expired, with no_worker. |
resultTtlSeconds |
--result-ttl |
60 to 86,400 | 86,400 | How long the finished job and its answer are kept. Then they are deleted. |
apidly endpoints submit EPN_ID /generate -d '{"prompt": "Hello"}' --queue-ttl 300 --result-ttl 3600
apidly endpoints job EPN_ID JOB_IDThe first line gives up on the job if no worker takes it within 5 minutes, and keeps the answer for an hour. The second shows the job's status. Through the API, add "queueTtlSeconds": 300, "resultTtlSeconds": 3600 to the job body. Both are checked once a minute, so a job can end up to a minute later than the exact time.
4. Roll back a broken update automatically
Changing an endpoint's template, disk size, variables or hardware starts a rolling update: new workers start, and old ones are released once the new ones are healthy. By default, when a new worker fails its health check, the update pauses and waits for you. With automatic rollback, it goes back to the earlier settings by itself.
- Open the endpoint and, in Scaling settings, turn on Roll back automatically.
- Select Save.
apidly endpoints update EPN_ID --auto-rollback onThrough the API, send {"autoRollback": true} with PATCH /api/v1/endpoints/EPN_ID. It is off by default.
When it acts, the activity list on the endpoint page shows Rolled back automatically. Old workers keep serving the whole time. It covers a new worker that fails its health check (three failed checks in a row after its start-up allowance, or not healthy within it). It does not cover a worker that could not be started at all, which still pauses the update; it never rolls back a second time; and after a template edit, where the earlier settings are unknown, the update pauses as usual.
What it costs and how to stop spending
None of these settings costs anything. Rejected requests and expired jobs never reach a worker. Workers are billed by the second while they run, including the extra workers of a rolling update or a rollback. To stop spending, select Pause on the endpoint page (all workers are released), or run apidly endpoints pause EPN_ID. Resume brings it back; apidly endpoints rm EPN_ID deletes it for good.
Next
Ready to try it?
Create a free account and add credit when you want to start a server. The smallest top-up is $10.
Was this helpful?