OpenAI ↗ helps you build with ChatGPT.
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai
When making requests to OpenAI, replace https://api.openai.com/v1
in the URL you’re currently using with https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai
.
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
--header 'Authorization: Bearer {openai_token}' \
--header 'Content-Type: application/json' \
"content": "What is Cloudflare"
If you’re using a library like openai-node, set the baseURL
to your OpenAI endpoint like this:
import OpenAI from "openai" ;
const apiKey = "my api key" ; // defaults to process.env["OPENAI_API_KEY"]
const accountId = "{account_id}" ;
const gatewayId = "{gateway_id}" ;
const baseURL = `https://gateway.ai.cloudflare.com/v1/ ${ accountId } / ${ gatewayId } /openai` ;
const openai = new OpenAI ( {
const model = "gpt-3.5-turbo-0613" ;
const messages = [ { role : "user" , content : "What is a neuron?" } ] ;
const chatCompletion = await openai . chat . completions . create ( {
const response = chatCompletion . choices [ 0 ] . message ;
return new Response ( JSON . stringify ( response )) ;