Advertisement
K0IN

openai proxy

Apr 5th, 2022 (edited)
1,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { listenAndServe } from "https://deno.land/[email protected]/http/server.ts";
  2.  
  3. async function handler(req) {
  4.     const apiKey = Deno.env.get("API_KEY");
  5.     const secret = Deno.env.get("API_SECRET");
  6.     if (secret !== req.headers.get("X-Secret")) {
  7.         return new Response("Hello world", { status: 200 });
  8.     }
  9.     return await fetch("https://api.openai.com/v1/engines/code-cushman-001/completions", {
  10.         headers: {
  11.             ...req.headers,
  12.             "Content-Type": "application/json",
  13.             Authorization: `Bearer ${apiKey}`,
  14.         },
  15.         method: req.method,
  16.         body: req.body,
  17.     });
  18. }
  19.  
  20. console.log("Listening on http://localhost:8080");
  21. await listenAndServe(":8080", handler);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement