weightsapi.추론콘솔
내비게이션
브라우저로 스트리밍

브라우저로 스트리밍

동일 출처 Node 서버가 API 키를 보관하고 SSE를 전달합니다.

요구 사항#

Node 22 이상. WEIGHTSAPI_API_KEY를 자신의 키로 설정하세요. AI 접근에는 로그인, 최소 100 USD의 확인된 충전 1회, 승인된 API 키, 요청에 충분한 사용 가능 크레딧이 필요합니다. 이후 각 충전도 최소 100 USD이며, 요청을 충당할 때 더 적은 잔액도 계속 사용할 수 있습니다. 크레딧은 거래 검증이 필요합니다. 트래픽을 보내기 전에 모델 가용성은 서비스 상태를 확인하세요.

레시피 실행#

// Node 22+. Save as server.mjs, set WEIGHTSAPI_API_KEY, then node server.mjs.
import http from "node:http";
const base = process.env.WEIGHTSAPI_BASE_URL || "https://weightsapi.com/v1";
http.createServer(async (req, res) => {
  if (req.url !== "/stream") {
    res.setHeader("Content-Type", "text/html");
    return res.end('<button id="run">Run</button><pre id="out"></pre><script>run.onclick=async()=>{out.textContent="";const r=await fetch("/stream");const reader=r.body.getReader();const decoder=new TextDecoder();for(;;){const {value,done}=await reader.read();if(done)break;out.textContent+=decoder.decode(value,{stream:true});}}<\/script>');
  }
  try {
    const upstream = await fetch(base+"/chat/completions", {method:"POST",
      headers:{"Content-Type":"application/json",Authorization:"Bearer "+process.env.WEIGHTSAPI_API_KEY},
      body:JSON.stringify({model:"Qwen/Qwen3-32B",messages:[{role:"user",content:"Explain SSE."}],stream:true,max_tokens:256})});
    res.writeHead(upstream.status, {"Content-Type":upstream.headers.get("content-type")||"text/plain","Cache-Control":"no-store"});
    for await (const chunk of upstream.body) res.write(chunk);
    res.end();
  } catch {res.writeHead(502);res.end("Upstream unavailable");}
}).listen(8080,"127.0.0.1");

프로덕션 전에#

동시성과 재시도를 제한하고, 출력을 검증하고, 오류를 처리한 다음 사용자에게 워크플로를 노출하세요.