A Cloudflare Worker which works in conjunction with https://github.com/indexxing/bsky-alt-text
1import { GoogleGenAI } from "@google/genai";
2import { Context, Next } from "hono";
3import { Env, Variables } from "../types";
4
5export async function geminiMiddleware(
6 c: Context<{ Bindings: Env; Variables: Variables }>,
7 next: Next,
8) {
9 if (!c.env || !c.env.GEMINI_API_KEY) {
10 return c.json({
11 success: false,
12 error: "Gemini API key is not specified in worker secrets.",
13 }, 500);
14 }
15
16 const genAI = new GoogleGenAI({
17 apiKey: c.env.GEMINI_API_KEY,
18 });
19 c.set("gemini", genAI);
20
21 await next();
22}