Generate Images with Amazon Bedrock
Amazon Bedrock is a fully managed service that offers a choice of high-performing foundation models (FMs) from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Mistral AI, Stability AI, and Amazon. Each model is accessible through a common API which implements a broad set of features to help build generative AI applications with security, privacy, and responsible AI in mind.
This guide will walk you through an example using the Amazon Bedrock JavaScript SDK in Supabase Edge Functions to generate images using the Amazon Titan Image Generator G1 model.
Setup
- In your AWS console, navigate to Amazon Bedrock and under "Request model access", select the Amazon Titan Image Generator G1 model.
- In your Supabase project, create a
.env
file in thesupabase
directory with the following contents:
Configure Storage
- [locally] Run
supabase start
- Open Studio URL: locally | hosted
- Navigate to Storage
- Click "New bucket"
- Create a new public bucket called "images"
Code
Create a new function in your project:
And add the code to the index.ts
file:
Run the function locally
- Run
supabase start
(see: https://supabase.com/docs/reference/cli/supabase-start) - Start with env:
supabase functions serve --env-file supabase/.env
- Make an HTTP request:
- Navigate back to your storage bucket. You might have to hit the refresh button to see the uploaded image.
Deploy to your hosted project
That's it, you've now deployed a serverless function that uses AI to generate and upload images to your Supabase storage bucket.