Cannot access Workers secret


I’m sorry, I’m unable to retrieve the secret (environment variable) that I defined in the worker’s dashboard within the worker itself. I specify the environment variable in the code, but it seems that the worker is unable to access it. I kindly request assistance.

Best regards,

this is my current code. The secret is the API-Key:

addEventListener(“fetch”, (event) => {

async function handleRequest(request) {
const url = new URL(request.url);
let apiUrl =;

// Erstellen Sie einen neuen Request und kopieren Sie einige Felder vom ursprünglichen Request
let apiRequest = new Request(apiUrl, request);
apiRequest.headers.set(“Authorization”, Bearer ${OPENAI_API_KEY}); // Verwenden Sie OPENAI_API_KEY direkt

// Führen Sie die Anfrage aus und senden Sie die Antwort zurück
let apiResponse = await fetch(apiRequest);
let response = new Response(apiResponse.body, apiResponse);

return response;

The names need to match

Hi, thank you for your quick replay.

Both names are matching “OPENAI_API_KEY”.