media-storage-ref

command
v1.5.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

Media Storage Reference Example

Send media to a vision model by a durable storage reference instead of inlining bytes on every request.

The caller stores an image once in a MediaStorageService, then passes a durable reference on each request. At model-call time the provider resolves that reference through the store — to a model-fetchable URL (via the store's GetURL) or to bytes. With a cloud-backed store the model fetches the presigned URL directly, so no image bytes transit the app on each turn.

What it shows

  • Creating a local disk-backed store with local.NewFileStore
  • Storing an image once with StoreMedia and getting back a Reference
  • Wiring the store into a conversation with sdk.WithMediaStorage
  • Sending the image by reference with sdk.WithImageStorageRef

Run it

export OPENAI_API_KEY=your-key   # or GEMINI_API_KEY / ANTHROPIC_API_KEY
go run .

The example writes the stored image under ./data. It generates a tiny PNG in code so it is fully self-contained — the point is the reference wiring, not the image content.

Test it (no keys needed)

go test ./ -count=1

The smoke test uses the mock provider and a real local store, asserting that Open + Send succeed with an image sent by reference.

Documentation

Overview

Package main demonstrates sending media to a vision model by durable storage reference with the PromptKit SDK.

Instead of inlining image bytes on every request, the caller stores the image once in a MediaStorageService and passes a durable reference. At model-call time the provider resolves that reference to a model-fetchable URL (or bytes) via the store. With a cloud store the model fetches the presigned URL directly, so no image bytes need to transit the app.

This example shows:

  • Creating a local disk-backed MediaStorageService
  • Storing an image once and getting back a durable reference
  • Wiring the store into the conversation with WithMediaStorage
  • Sending the image by reference with WithImageStorageRef

Run with:

export OPENAI_API_KEY=your-key
go run .

Alternatively set GEMINI_API_KEY or ANTHROPIC_API_KEY and the SDK will select the matching vision-capable provider from the environment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL