요구 사항#
Python 3.11 이상. 추가 패키지 불필요. WEIGHTSAPI_API_KEY를 자신의 키로 설정하세요. AI 접근에는 로그인, 최소 100 USD의 확인된 충전 1회, 승인된 API 키, 요청에 충분한 사용 가능 크레딧이 필요합니다. 이후 각 충전도 최소 100 USD이며, 요청을 충당할 때 더 적은 잔액도 계속 사용할 수 있습니다. 크레딧은 거래 검증이 필요합니다. 트래픽을 보내기 전에 모델 가용성은 서비스 상태를 확인하세요.
레시피 실행#
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"))
프로덕션 전#
이 라우팅 규칙은 검증된 난이도 분류기가 아니라 투명한 휴리스틱입니다. 비용 절감에 의존하기 전에 자신의 워크로드에 대해 평가하세요.