I'm also interested in having the AI

I'm also interested in having the AI gateway store API keys and protect that with cloudflare zero trust. I'm currently doing that with a worker but I'm curious if there are plans to support secrets management natively
1 Reply
alex | zellic.io
alex | zellic.ioOP16mo ago
const cfProxy = "https://gateway.ai.cloudflare.com/v1/asdasdasdas/dsasadsdas/openai/chat/completions";

export interface Env {
OPENAI_API_KEY: string;
}

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url);

request = new Request(cfProxy, request)

request.headers.set("Authorization", `Bearer ${env.OPENAI_API_KEY}`);

let response = await fetch(request);

response = new Response(response.body, response);
response.headers.set("Access-Control-Allow-Origin", url.origin);

// Append to/Add Vary header so browser will cache response correctly
response.headers.append("Vary", "Origin");

return response;
},
};
const cfProxy = "https://gateway.ai.cloudflare.com/v1/asdasdasdas/dsasadsdas/openai/chat/completions";

export interface Env {
OPENAI_API_KEY: string;
}

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url);

request = new Request(cfProxy, request)

request.headers.set("Authorization", `Bearer ${env.OPENAI_API_KEY}`);

let response = await fetch(request);

response = new Response(response.body, response);
response.headers.set("Access-Control-Allow-Origin", url.origin);

// Append to/Add Vary header so browser will cache response correctly
response.headers.append("Vary", "Origin");

return response;
},
};
this is a bit clunky and only works for openai reqs. this worker is protected with access and the secret is stored in worker secrets.

Did you find this page helpful?