weightsapi.INFERENCEConsole
Navigation
Route by task difficulty

Route by task difficulty

An explicit heuristic routes short tasks and complex analysis.

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, urllib.request
BASE = os.environ.get("WEIGHTSAPI_BASE_URL", "https://weightsapi.com/v1")
KEY = os.environ["WEIGHTSAPI_API_KEY"]
def chat(messages, model="Qwen/Qwen3-32B", **options):
    payload = dict(model=model, messages=messages, max_tokens=512, **options)
    req = urllib.request.Request(BASE+"/chat/completions", json.dumps(payload).encode(),
        {"Authorization": "Bearer "+KEY, "Content-Type": "application/json"})
    with urllib.request.urlopen(req, timeout=120) as response:
        return json.load(response)
question = input("Question: ")
complex_task = len(question) > 300 or any(w in question.lower() for w in ("prove", "derive", "analyze", "debug"))
model = "deepseek-ai/DeepSeek-R1-0528" if complex_task else "meta-llama/Llama-3.1-8B-Instruct"
response = chat([{"role":"user","content":question}], model=model)
print("Selected:", model)
print(response["choices"][0]["message"]["content"])
print("Usage:", response.get("usage"))

Before production#

This routing rule is a transparent heuristic, not a validated difficulty classifier. Evaluate it against your workload before relying on cost savings.