K0IN icon

openai proxy

K0IN | PRO | 04/05/22 07:06:05 PM UTC (Edited) | 0 ⭐ | 7824 👁️ | Never ⏰ | []
TypeScript |

720 B

|

None

|

0 👍

/

0 👎

import { listenAndServe } from "https://deno.land/[email protected]/http/server.ts";
 
async function handler(req) {
    const apiKey = Deno.env.get("API_KEY");
    const secret = Deno.env.get("API_SECRET");
    if (secret !== req.headers.get("X-Secret")) {
        return new Response("Hello world", { status: 200 });
    }
    return await fetch("https://api.openai.com/v1/engines/code-cushman-001/completions", {
        headers: {
            ...req.headers,
            "Content-Type": "application/json",
            Authorization: `Bearer ${apiKey}`,
        },
        method: req.method,
        body: req.body,
    });
}
 
console.log("Listening on http://localhost:8080");
await listenAndServe(":8080", handler);

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎