npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sanity-plugin-gemini-ai-images-serverless

v1.1.0

Published

Serverless adapter for Sanity Gemini AI Image Generator (Vercel, Netlify, etc.)

Downloads

10

Readme

sanity-plugin-gemini-ai-images-serverless

Serverless adapter for the Sanity Gemini AI Image Generator plugin.

Works with Vercel Functions, Netlify Functions, AWS Lambda, and other serverless platforms.

Installation

npm install sanity-plugin-gemini-ai-images sanity-plugin-gemini-ai-images-serverless @google/genai

Setup

1. Add Plugin to Sanity Config

// sanity.config.ts
import {defineConfig} from 'sanity'
import {geminiAIImages} from 'sanity-plugin-gemini-ai-images'

export default defineConfig({
  plugins: [
    geminiAIImages({
      apiEndpoint: '/api/gemini/generate-image', // or your custom path
    }),
  ],
})

2. Create Serverless Function

Vercel Functions:

// api/gemini/generate-image.ts
import {handler} from 'sanity-plugin-gemini-ai-images-serverless'

export default handler

Netlify Functions:

// netlify/functions/generate-image.ts
import {handler} from 'sanity-plugin-gemini-ai-images-serverless'

export {handler}

AWS Lambda (with API Gateway):

// lambda/generate-image.ts
import {handler} from 'sanity-plugin-gemini-ai-images-serverless'

export {handler}

3. Set Environment Variables

Vercel:

# .env or Vercel Dashboard
GEMINI_API_KEY=your_api_key_here
SANITY_PROJECT_ID=your_project_id
SANITY_DATASET=production

Netlify:

# netlify.toml or Netlify Dashboard
[build.environment]
  GEMINI_API_KEY = "your_api_key_here"
  SANITY_PROJECT_ID = "your_project_id"
  SANITY_DATASET = "production"

AWS Lambda: Set via AWS Console → Lambda → Configuration → Environment variables:

  • GEMINI_API_KEY: your_api_key_here
  • SANITY_PROJECT_ID: your_project_id
  • SANITY_DATASET: production

Get your Gemini API key from Google AI Studio.

Important:

  • The Sanity project ID and dataset are required for authentication verification
  • These should match your Sanity Studio configuration

Platform-Specific Notes

Vercel

  • Function timeout: Default is 10s, but image generation may take longer
  • Increase timeout in vercel.json:
{
  "functions": {
    "api/gemini/generate-image.ts": {
      "maxDuration": 60
    }
  }
}

Netlify

  • Function timeout: Default is 10s for free tier, 26s for Pro
  • For longer timeouts, upgrade to Pro or use background functions
  • Configure in netlify.toml:
[functions]
  directory = "netlify/functions"

[[functions."generate-image"]]
  timeout = 26

AWS Lambda

  • Default timeout is 3s - increase to at least 60s
  • Configure memory to at least 1024MB for better performance
  • Enable function URL or use API Gateway

Cloudflare Workers

Not currently supported due to Workers' runtime limitations. Consider using Cloudflare Pages Functions instead, which support Node.js APIs.

Custom Endpoint Path

If your function is at a different path, update the Sanity config:

geminiAIImages({
  apiEndpoint: '/api/custom/ai-images',
})

Requirements

  • Node.js 20.0.0 or higher
  • Sanity Studio v4
  • Serverless platform that supports Node.js runtime

Authentication

This adapter automatically verifies that requests come from authenticated Sanity Studio users. The authentication flow works as follows:

  1. The core plugin (in Sanity Studio) retrieves the user's token from the Sanity client
  2. The token is sent in the Authorization: Bearer <token> header with each request
  3. The adapter verifies the token against the Sanity API before processing the image generation request

This ensures that only authenticated Sanity Studio users can generate images through your API endpoint.

Troubleshooting

Function Timeout

Image generation can take 10-30 seconds. Increase your function timeout:

  • Vercel: Use vercel.json (see above)
  • Netlify: Upgrade to Pro for 26s timeout
  • AWS Lambda: Increase in function configuration

CORS Errors

The handler includes CORS headers by default. If you still see errors, check your platform's CORS configuration.

Cold Starts

First request may be slow due to cold starts. This is normal for serverless functions.

Unauthorized Error (401)

If you receive "Unauthorized" errors:

  • Ensure you're logged into Sanity Studio
  • Verify SANITY_PROJECT_ID and SANITY_DATASET environment variables are set correctly
  • Check that the environment variables match your Sanity Studio configuration
  • Make sure your serverless platform has the environment variables configured
  • Note: Use SANITY_PROJECT_ID (not NEXT_PUBLIC_SANITY_PROJECT_ID) in serverless environments

License

MIT © Nick Jensen