> This page location: Functions > Templates > Image analysis with AI Gateway
> Full Neon documentation index: https://neon.com/docs/llms.txt

# Image analysis with AI Gateway

Describe an uploaded image with structured details using a vision model on Neon AI Gateway.

- First Party: maintained by Neon
- Built by: Neon
- Categories: First Party, AI
- Built with: [AI Gateway](https://neon.com/docs/ai-gateway/overview.md)

## Install

```bash
neon functions new image-analysis
```

## About this template

This Neon Function sends an uploaded image to a vision model through [Neon AI Gateway](https://neon.com/docs/ai-gateway/overview) 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:

```bash
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:

```bash
neon config add ai-gateway
```

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

AI Gateway requires prepaid credits and a project in a supported region. See the [AI Gateway quickstart](https://neon.com/docs/ai-gateway/get-started) and [prepaid credits](https://neon.com/docs/ai-gateway/prepaid-credits).

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

```bash
neon deploy
```

### Run locally

```bash
neon dev
```

Upload an image to the URL that `neon dev` prints, which defaults to `http://localhost:8787/`:

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

The response looks like this:

```json
{
  "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/imageanalysis/index.ts` to use another vision model from the [AI Gateway catalog](https://neon.com/docs/ai-gateway/overview#available-models).

## Related

- Previous: [Context.dev web data](https://neon.com/functions/templates/context-dev.md)
- Next: [Support triage with Jev](https://neon.com/functions/templates/jev-triage.md)
- [All templates](https://neon.com/functions/templates.md)
- [Template source](https://github.com/neondatabase/examples/tree/main/registry/image-analysis)
- [Use function templates](https://neon.com/docs/compute/functions/templates.md)
- [Contribute a function template](https://neon.com/docs/compute/functions/registry.md)

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/functions/templates/image-analysis"}` to https://feedback.neon.tech/ (no auth required).