Requirements#
Python 3.11 or newer. No additional packages. Set WEIGHTSAPI_API_KEY to your own key. AI access requires sign-in, one confirmed top-up of at least USD 100, an authorized API key and enough available credit for the request. Each later top-up also has a USD 100 minimum; smaller remaining balances stay usable when they cover the request. Credit requires transaction verification. Check service status for model availability before sending traffic.
Run the recipe#
import os, json, time, urllib.request
BASE = os.environ.get("WEIGHTSAPI_BASE_URL", "https://weightsapi.com/v1")
KEY = os.environ["WEIGHTSAPI_API_KEY"]
# Confirm batch-service availability before attempting upload or submission.
with open("batch.jsonl", "w", encoding="utf-8") as f:
for i in range(100_000):
f.write(json.dumps({"custom_id":str(i),"method":"POST","url":"/v1/chat/completions",
"body":{"model":"Qwen/Qwen3-32B","messages":[{"role":"user","content":"Summarize document "+str(i)}],"max_tokens":64}})+"\n")
print("Wrote 100,000 independent requests to batch.jsonl.")
print("Upload with the provider's batch adapter, then submit /v1/batches with completion_window=24h.")
print("Do not send this file to the synchronous endpoint: the batch discount applies only to batch jobs.")
Before production#
This recipe creates a JSONL file locally. Upload, submission and result retrieval require a supported batch deployment. Check service status and confirm the batch terms before submitting a workload; a listed discount or completion window does not guarantee job acceptance.