Many applications already speak the OpenAI chat API. If your model sits behind the same protocol, moving to it means changing a base URL and a model name, not rewriting code. This post sets up an open-weights model on an Apidly serverless endpoint, which runs a vLLM server on GPU workers that start on demand, and calls it three ways: curl, the OpenAI Python client and the Apidly Python SDK. It also covers the one behaviour that surprises people, the cold start.
What you are building
An endpoint gives you one HTTPS address in front of an HTTP server. Behind it are GPU workers, between a minimum and a maximum you choose. Requests go to a ready worker; if none is ready, the request waits while one starts. Idle workers are released after a timeout. Each worker is an ordinary server billed by the second, with no per-request price (see per-second vs hourly billing for worked numbers). Endpoints may not be switched on for every account yet; if you do not see Endpoints in the console, they are not available to you.
Step 1: Create an API key
In the console open API keys, create a key with the Servers permission and store it in your shell:
export APIDLY_API_KEY="paste-your-key-here"Keys are shown once. A key with the read scope cannot create endpoints or wake workers.
Step 2: Preview the choice with a dry run
If you only want a chat model behind an OpenAI-compatible address, you do not have to pick a GPU or a template. Send the model name and ask for a dry run, which creates nothing:
curl -X POST "https://apidly.com/api/v1/endpoints?dryRun=1" \
-H "Authorization: Bearer $APIDLY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"Qwen/Qwen2.5-7B-Instruct"}'The answer's fromModel object names the plan and template the server chose, the disk, the estimated GPU memory and the prices: workerHourlyUsd for one worker, and minHourlyUsd and maxHourlyUsd for the fewest and most workers. The GPU memory is an estimate from the model's weights, its context and a margin. If you want to check that estimate yourself, the GPU sizing guide shows how to derive it from the model's config.json.
Some models need extra care:
- A gated model needs an access token. Accept its license on the model page, store the token as a secret in the console, and pass the secret's name as
hfTokenSecret. Workers receive a reference to the secret, never its value. - Only chat and text models in the standard Hub format work this way. Embeddings, image and speech models, and GGUF builds need a template chosen by hand.
Step 3: Create the endpoint
The same call without dryRun creates it. It starts with a minimum of 0 workers and a maximum of 1, so nothing is billed once the idle timeout has released the worker. You can change both later.
curl -X POST "https://apidly.com/api/v1/endpoints" \
-H "Authorization: Bearer $APIDLY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: my-first-endpoint-1" \
-d '{"model":"Qwen/Qwen2.5-7B-Instruct"}'The Idempotency-Key header is optional but makes a retry safe: the same key and body return the same endpoint instead of creating a second one. The answer holds the endpoint under endpoint, with its id. Use that id wherever EPN_ID appears below.
In Python, with the Apidly SDK (install it from the SDK page in the docs; it uses only the standard library):
import os
from apidly import Client
client = Client(api_key=os.environ["APIDLY_API_KEY"])
choice = client.endpoints.create_from_model("Qwen/Qwen2.5-7B-Instruct", dry_run=True)
print(choice["fromModel"]["workerHourlyUsd"], choice["fromModel"]["gpuMemoryGb"])
created = client.endpoints.create_from_model("Qwen/Qwen2.5-7B-Instruct", max_workers=2)
endpoint_id = created["endpoint"]["id"]The SDK sends a random idempotency key on a real create unless you pass one. The CLI has the same flow: apidly endpoints create --model Qwen/Qwen2.5-7B-Instruct --dry-run, then the same without --dry-run.
Step 4: Call it with curl
Send requests to the endpoint's OpenAI base URL, https://apidly.com/api/v1/endpoints/EPN_ID/openai/v1. Every path under it goes to the server's /v1/...:
curl -i https://apidly.com/api/v1/endpoints/EPN_ID/openai/v1/chat/completions \
-H "Authorization: Bearer $APIDLY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen2.5-7B-Instruct",
"messages": [{"role": "user", "content": "Explain a KV cache in two sentences."}],
"stream": true
}'Streaming works as the server sends it, server-sent events included. A single request can last at most 300 seconds, waiting included, so stream long generations.
Step 5: The cold start
With a minimum of zero workers, the first request after a quiet period finds no worker. The platform notices the waiting request, finds a machine, the worker loads the model, and the health check marks it ready. That can take several minutes, and a request is held for at most 240 seconds. For a model server, the first request therefore often returns 503 with a Retry-After header while the worker is still loading. That is the system working as designed, not a failure. Code that calls the endpoint should retry on 503 after the number of seconds given.
Two codes to know: a 503 with the code queue_timeout means the wait ran out while a worker was starting; no_worker_ready means the endpoint has a longest wait of zero. If your account is new, the first worker may wait for staff review before it starts.
Step 6: The OpenAI Python client
Because the endpoint speaks the protocol, the standard client works. Turn off its own retries and handle 503 yourself, so you can honour Retry-After:
import os
import time
from openai import APIStatusError, OpenAI
client = OpenAI(
base_url="https://apidly.com/api/v1/endpoints/EPN_ID/openai/v1",
api_key=os.environ["APIDLY_API_KEY"],
max_retries=0,
)
for attempt in range(60):
try:
reply = client.chat.completions.create(
model="Qwen/Qwen2.5-7B-Instruct",
messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(reply.choices[0].message.content)
break
except APIStatusError as e:
if e.status_code != 503:
raise
wait = int(e.response.headers.get("Retry-After", "10"))
print(f"No worker ready yet. Trying again in {wait} s.")
time.sleep(wait)The same works in JavaScript with baseURL and apiKey set on the OpenAI constructor.
Step 7: The Apidly Python SDK
The SDK exposes the same route through client.endpoints.openai, which takes the endpoint id and the path under the base URL. It parses the JSON answer. A POST is not retried automatically (only calls made safe with an idempotency key are), so keep a loop for cold starts and branch on the typed error:
import os
import time
from apidly import ApiError, Client
client = Client(api_key=os.environ["APIDLY_API_KEY"])
endpoint_id = "EPN_ID"
print(client.endpoints.openai(endpoint_id, "models", method="GET"))
body = {
"model": "Qwen/Qwen2.5-7B-Instruct",
"messages": [{"role": "user", "content": "Say hello in five words."}],
}
for _ in range(60):
try:
answer = client.endpoints.openai(endpoint_id, "chat/completions", body)
print(answer["choices"][0]["message"]["content"])
break
except ApiError as e:
if e.status != 503:
raise
time.sleep(e.retry_after or 10)ApiError carries status, a stable code, retry_after (seconds, from the header) and request_id. Branch on code, not on the message. Use client.endpoints.get(endpoint_id) to see the workers and recent scaling events, and client.endpoints.metrics(endpoint_id, window="24h") for requests, latency percentiles, cold starts and cost per 1,000 calls.
Things that go wrong
422 chat_template_missing./v1/chat/completionsneeds a model that ships a chat template. For a base model without one, send a plain prompt to/v1/completions.- Context length. The vLLM worker template limits prompt plus answer through the
MAX_MODEL_LENvariable (8,192 by default). A lower value needs less GPU memory; a larger one needs more. - Same user, same worker. Send an
X-Session-Idheader (1 to 128 letters, digits and._:-) and requests with the same value reach the same worker while it is ready, which helps when workers keep per-conversation state. - A model cache. A new worker usually starts on another machine and downloads the weights again. A model cache gives a worker's disk room for the weights, so a worker that is stopped into a warm pool or restarted finds them again. It is billed as disk, for every worker that exists.
Keep it cheap and bounded
Leave the minimum at zero unless you cannot accept a cold start; then set it to 1 and accept that one worker is billed all the time. Set a spending cap per hour and a monthly cap before you share the address, create separate keys for each application, and pause or delete the endpoint when you are finished: Pause releases all workers and nothing is billed, while Stop keeps the disks, and disks are billed.
Try what this guide shows
Start one of these templates on a cloud GPU server. You see the price per hour before you start, and you pay by the second.
- Language modelsOpens in your browser
vLLM (OpenAI-compatible)
High-throughput LLM inference server exposing an OpenAI-compatible API on port 8000.
- Minimum GPU memory
- 16 GB
- Default disk
- 100 GB
- Language modelsOpens in your browser
LiteLLM gateway (one API for many models)
One OpenAI-style address in front of your own models and other providers, protected by a key.
- Minimum GPU memory
- No minimum
- Default disk
- 20 GB
Try it on a real GPU server
Create a free account and add a balance from $10. Servers are billed by the second, and the review step shows the price per hour before you request one.
Related guides
- Run an open LLM with vLLM on a cloud GPUServe Qwen or another open model behind an OpenAI-compatible API on a cloud GPU with vLLM: pick the GPU, set the model, call it from code and stop when idle.
- Pick a GPU for LLM inference: VRAM and speedSize a GPU from public model facts: weight memory, KV cache, quantization and the memory-bandwidth limit on decode speed.
- How billing by the second worksHow compute and storage are charged by the second on Apidly, with worked examples.