Skip to content

Instantly share code, notes, and snippets.

@Dhravya
Created July 14, 2025 03:06
Show Gist options
  • Save Dhravya/f1a26f7ff73f1b219ef03bec271c2ca3 to your computer and use it in GitHub Desktop.
Save Dhravya/f1a26f7ff73f1b219ef03bec271c2ca3 to your computer and use it in GitHub Desktop.
Workers AI universal endpoint broken
// import { createAnthropic } from "@ai-sdk/anthropic"
// import { createGroq } from "@ai-sdk/groq"
// import { createGoogleGenerativeAI } from "@ai-sdk/google"
import { createOpenAI } from '@ai-sdk/openai';
import { createAiGateway } from '../../packages/ai-gateway-provider/src/index.js';
import { generateText } from 'ai';
export default {
async fetch() {
const originalFetch = fetch;
globalThis.fetch = function (...args) {
console.log('Request URL:', args[0]);
console.log('Request options:', args[1]);
if (args[1] && args[1].body) {
console.log('Request body:', args[1].body);
}
return originalFetch.apply(this, args);
};
const openai = createOpenAI({
apiKey:
'sk-proj-OPENAI_KEY',
});
const aigateway = createAiGateway({
accountId: '',
gateway: 'supermemory-dev',
apiKey: '',
});
const textModel = aigateway([
// groq("llama3-70b-8192"),
openai('gpt-4o'),
]);
console.log('Testing API key passthrough with authenticated AI Gateway...');
console.log('Using Gateway: supermemory-dev');
console.log('Account ID:', process.env.CLOUDFLARE_ACCOUNT_ID);
const output = await generateText({
model: textModel,
prompt: 'Hello! Please respond with a simple greeting to test API key passthrough.',
});
console.log('✅ Success! API keys are being passed through correctly.');
console.log('Response:', output.text);
return new Response(output.text);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment