This Neon Function sends an uploaded image to a vision model through Neon AI Gateway and returns a description and structured details.

Send a multipart/form-data request with an image file.

Scaffold it

Install the latest Neon CLI, then create the function from the registry:

npm install -g neon@latest
neon login
neon link
neon functions new image-analysis --slug imageanalysis

The CLI writes functions/imageanalysis/index.ts and declares the function in neon.ts.

Enable AI Gateway on the linked branch:

neon config add ai-gateway

You can also set aiGateway: true in neon.ts.

AI Gateway requires a paid Neon plan with prepaid credits and a project in a supported region. See the AI Gateway quickstart.

Deploy once so Neon provisions the gateway and injects NEON_AI_GATEWAY_BASE_URL and NEON_AI_GATEWAY_TOKEN into .env.local:

neon deploy

Run locally

neon dev

Call the URL that neon dev prints (the default is http://localhost:8787/). Upload an image:

curl -X POST http://localhost:8787/ \
  -F "image=@./photo.jpg"

Example response:

{
  "description": "A tabby cat stands on a paved path...",
  "details": {
    "subjects": ["tabby cat"],
    "setting": "outdoors on a paved path",
    "text": [],
    "tags": ["cat", "animal", "outdoors", "pavement"]
  },
  "model": "gpt-5-mini"
}

Request format

Send POST / with one image field that holds an image file with an image/* content type, up to 10 MB.

A missing image returns 400, an image over 10 MB returns 413, a non-image file returns 415, and an analysis failure returns 502.

This template doesn't authenticate requests, so anyone with the function URL can call it and spend AI Gateway credits. Add authentication before you expose it.

The template uses gpt-5-mini, which accepts image input. Change MODEL in functions/index.ts to use another vision model from the AI Gateway catalog.