Skills for AI/ML API, one API for 10,000+ AI models and tools: choosing models, chat on any protocol, images, video and audio jobs, speech, decision models, webhooks, batches, errors, costs and sandbox testing
93%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Medium
Suggest reviewing before use
A batch runs a JSONL file of /v1/chat/completions requests within 24 hours at the model's batch price (for most providers half the list price). The format is OpenAI's: with the OpenAI SDK, files.create, batches.* and files.content work after changing base_url.
failed or expired, or its result file will not downloadNot for: anything a user is waiting for (aimlapi-chat); images, audio, embeddings (only chat lines are accepted).
curl -s 'https://api.aimlapi.com/v1/models?id=anthropic/claude-haiku-5-5&include=pricing'Only a model whose entry has pricing.batch can run; use its id exactly as listed. Some short aliases (gpt-5.5, o3) route to another provider and are refused with model_not_supported_for_batch.
{"custom_id": "review-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "anthropic/claude-haiku-5-5", "max_tokens": 5, "messages": [{"role": "user", "content": "Sentiment of: 'Great product'. One word."}]}}max_tokens (or max_completion_tokens) on every line, as low as the task allows: the hold is priced from it.custom_id unique, up to 512 characters. Text and function tools only; no images, audio or server tools; stream false, n 1. Other fields fail the line. cache_control is accepted, so long shared instructions can be cached.python3 scripts/batch.py check requests.jsonlAt most 3 batches and 100,000 lines in progress per account (a fourth create gets 429 batch_limit_exceeded with Retry-After). A file is at most 50 MiB in one request, 200 MiB in parts, and under its provider's cap (Anthropic 100,000 lines, OpenAI 50,000). A large job is a queue: split into files under the limits, keep at most 3 running, start the next when one ends. More limits: references/limits-and-errors.md.
python3 scripts/batch.py run requests.jsonl --out results/The script uploads (single request or parts), creates the batch, polls, and saves the output and error files. A re-run on the same file resumes its batch (state in <file>.aimlapi-batch.json); a changed file stops. In the user's own code:
Idempotency-Key (up to 255 characters, from the file content); store the batch id before polling./v1/uploads: POST /v1/uploads → POST /v1/uploads/{id}/parts {"part_number": n} → PUT the bytes to the returned url (no Authorization; parts ≥ 5 MiB except the last) → POST /v1/uploads/{id}/complete with {"parts": [{"part_number", "etag"}]} → file.id. The OpenAI SDK's uploads.* helpers do not work here.GET /v1/files/{id}/content: it redirects (302) to a signed link valid 5 minutes. Follow it without the Authorization header (requests and the OpenAI SDK do; Python's urllib does not).webhook_url on create (aimlapi-webhooks).validating, in_progress, finalizing, cancelling are still running.completed means the batch ran to the end, even if every line failed: read request_counts and the error file.failed means it was refused as a whole (file check, hold, provider): errors lists up to 100 problems with line numbers, and nothing is charged.expired and cancelled: finished lines are in the output file and charged, the rest in the error file.Output lines come in any order: join them by custom_id; response.body is a Chat Completions response. Line and errors shapes: references/limits-and-errors.md. Error-file lines are not charged. Result files are deleted after 30 days.
Idempotency-Key, and poll the stored id after a crash.max_tokens sized to the task. A hold over 80 % of the available balance fails the batch with batch_hold_over_balance_share.409)."requests": [...] format.| Symptom | Do |
|---|---|
400 model_not_supported_for_batch | step 1 |
400 Line 1: …, or batch failed with errors[].line | fix those lines (batch.py check), upload, create again |
batch failed with insufficient_credits, batch_hold_over_balance_share, key_quota_exceeded | lower max_tokens, split, or top up |
429 batch_limit_exceeded | wait Retry-After; keep ≤ 3 running |
| result download fails with an auth error | step 4, follow the redirect without Authorization |
Every code: references/limits-and-errors.md.
python3 scripts/batch.py check requests.jsonl reports no problems.custom_id, reads the error file, runs at most 3 batches.scripts/batch.py: check, upload (single or parts), create, wait, download, cancel