weightsapi.推理控制台
导航
批量处理十万份文档

批量处理十万份文档

准备一个 JSONL 批处理文件,提交它,然后轮询输出文件。

要求#

Python 3.11 或更高版本。无需额外包。将 WEIGHTSAPI_API_KEY 设置为您的密钥。AI 访问需要登录、一次至少 100 美元的确认充值、一个已授权的 API 密钥以及足够的可用余额。每次后续充值的最低金额也为 100 美元;较小的剩余余额在足以支付请求时仍可使用。余额需要交易验证。发送流量前请查看服务状态 了解模型可用性。

运行配方#

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.")

生产之前#

此配方在本地创建 JSONL 文件。上传、提交和结果检索需要支持的批处理部署。提交工作负载前请查看服务状态 并确认批处理条款;列出的折扣或完成窗口不保证作业被接受。