Running it
Going to production
What a client needs before it runs without you: time-outs, retry rules, safe repeats, the numbers to watch and a checklist.
In short
- Set the time-out of your client to at least 35 seconds when you send
Prefer: wait=30. - Retry only
429,503and lost answers. Do not send a500or another4xxagain unchanged. - Send an
Idempotency-Keywith everyPOST /v1/solves. A repeat is then not charged. - Keep keys on your server, and log the
Request-Idof every answer.
Time-outs
- Set the time-out of your HTTP client to at least 35 seconds when you send
Prefer: wait=30. Many clients stop at 30 seconds by default. - Allow about 90 seconds in total for a first solve after a quiet period: the solver must start.
- A large request can run for hours. Put a limit of your own on how long you wait, and cancel what you no longer need.
Retry rules
| Answer | What to do |
|---|---|
429 | Wait the seconds in Retry-After, then send the same request. |
503, or no answer (a network error or a time-out) | Send it again after 1, 2, 4 and 8 seconds: at most 5 tries. Use Retry-After when the answer has it; a 503 also has the seconds as retry_after in its body. |
409 request_in_progress | Wait the seconds in Retry-After, then send the same request. |
500 | Do not send it again unchanged. Contact us with the request id. |
Any other 4xx | Do not send it again unchanged. Change the request, the key or the account first. |
What is safe to repeat
- Every
GETis safe to repeat. So arePOST /v1/estimates,POST /v1/trees,POST /v1/warmupandPOST /v1/solves/{id}/cancel. POST /v1/solvesis safe to repeat only with anIdempotency-Key. Without one, each send is a new request and is charged.
How an Idempotency-Key works, and what it remembers
An Idempotency-Key is 8 to 128 characters that you choose, such as a UUID. It is remembered for 24 hours, for one account and one mode (test and live are apart). A repeat with the same body gets the first answer again and charges nothing more.
A repeat with another body is 409 idempotency_conflict. A repeat that arrives while the first is still being created is 409 request_in_progress.
A refusal is remembered only when it made a solve record: such a refusal has a solve_id in its body, and a repeat gets the same refusal again. A request that a check refused made nothing: a 422 for a field or a limit, or a 402 for an estimate above your balance.
Its key is free, and the same key with a corrected body is accepted. See refusals that leave a record.
# the second send gets the first solve again and is not charged
IDEM=$(uuidgen)
for attempt in 1 2; do
curl -sS -X POST "$GECKO_API/v1/solves" \
-H "Authorization: Bearer $GECKO_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: $IDEM" -H "Prefer: wait=30" \
-d @spot.json | jq -r .id
done
import time, uuid
def send(method, path, tries=5, **kwargs):
"""A request with the retry rules: 429 and 503 wait and go again, a lost answer goes again, the rest returns."""
for attempt in range(tries):
try:
response = requests.request(method, API + path, timeout=40, **kwargs)
except (requests.ConnectionError, requests.Timeout):
response = None
if response is not None and response.status_code not in (429, 503):
return response
retry_after = response.headers.get("Retry-After") if response is not None else None
time.sleep(min(float(retry_after or 2 ** attempt), 30)) # 1, 2, 4, 8 seconds
raise RuntimeError("The API did not answer. Stop and look before you send more.")
key = str(uuid.uuid4()) # one key for one request, kept across the retries
headers = {**WAIT, "Idempotency-Key": key}
first = send("POST", "/v1/solves", json=spot, headers=headers).json()
again = send("POST", "/v1/solves", json=spot, headers=headers).json()
print(first["id"] == again["id"]) # True: one solve, charged one time
import { randomUUID } from "node:crypto";
// A request with the retry rules: 429 and 503 wait and go again, a lost answer goes again, the rest returns.
async function send(method, path, { headers = auth, body, tries = 5 } = {}) {
for (let attempt = 0; attempt !== tries; attempt++) {
let response = null;
try {
response = await fetch(API + path, {
method,
headers: body ? { ...headers, "Content-Type": "application/json" } : headers,
body: body ? JSON.stringify(body) : undefined,
signal: AbortSignal.timeout(40_000),
});
} catch { /* a network error or a time-out: go again */ }
if (response && ![429, 503].includes(response.status)) return response;
const seconds = Number(response?.headers.get("Retry-After")) || 2 ** attempt; // 1, 2, 4, 8 seconds
await new Promise((done) => setTimeout(done, Math.min(seconds, 30) * 1000));
}
throw new Error("The API did not answer. Stop and look before you send more.");
}
const idem = { ...wait, "Idempotency-Key": randomUUID() }; // one key for one request, kept across the retries
const one = await (await send("POST", "/v1/solves", { headers: idem, body: spot })).json();
const two = await (await send("POST", "/v1/solves", { headers: idem, body: spot })).json();
console.log(one.id === two.id); // true: one solve, charged one time
Look it up
Go-live checklist
eleven points to check
- Your flow runs from start to end with a test key, with your own spots.
- Your account has calls or a plan (see Go live).
- The live key is in a secret store on your server. It has a daily limit.
- The client time-out is at least 35 seconds. The first solve after a quiet period is allowed about 90 seconds.
- You retry only
429,503and lost answers, with the waits above. POST /v1/solvescarries anIdempotency-Keywherever your code can send it two times.- Large requests carry
max_credits, and you ask for an estimate first. - Your reading code accepts a missing hand, a missing node and a missing exit.
- You store the results you need within 6 days, with the solve id and the
model_id. - You log the
Request-Idof every answer. - Your use fits the fair use rules: no help to a player during a hand.
Rate limits
120 requests a minute for a key
Each key may send 120 requests a minute. Every answer to a call that reached the check of the key has RateLimit-Limit (the limit) and RateLimit-Remaining (what is left now). The headers are not on the open routes (/v1/health, /v1/hands, /v1/pricing), on a 401, on a 404 for a route that does not exist, on a 405, on a 413, or on a body that is not JSON.
The count fills again evenly: two a second at 120 a minute. Above the limit the answer is 429 rate_limited with Retry-After. A wait with Prefer: wait=30 is one request, so waiting this way stays far below the limit.
curl -sS -D - -o /dev/null "$GECKO_API/v1/account" -H "Authorization: Bearer $GECKO_KEY" \ | grep -i -E "ratelimit|request-id"
Request ids
Every answer has a Request-Id header, and every error has the same id as request_id in its body. Write it to your log with the solve id. When you ask us about a request, send the request id.
No webhooks
The API does not call you back. To know when a solve or a request is finished, wait with Prefer: wait or ask again: see Waiting for a result. There is no client library: the API is plain HTTP with JSON.
Throughput
one solve at a time
By default an account has one solve at the solver at a time, and capacity is shared between accounts. A request of N solves takes about N times the typical seconds in GET /v1/health, and longer when others wait too.
Sending more requests at the same time does not make it faster: they wait in the same line. Ask us for more solves at one time.
Keys
Keep keys on your server, use one key for each service, and rotate a key without a gap: see keep and rotate keys.