Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: temp test api endpoint for bedrock (#36668)

Greg Richardsondd66bbbcdd87
diff --git a/apps/studio/middleware.ts b/apps/studio/middleware.ts
index 339d6116acd..5ba40012d41 100644
--- a/apps/studio/middleware.ts
+++ b/apps/studio/middleware.ts
@@ -14,6 +14,7 @@ const HOSTED_SUPPORTED_API_URLS = [
'/ai/sql/title',
'/ai/sql/cron',
'/ai/feedback/classify',
+ '/ai/temp/bedrock-test',
'/get-ip-address',
'/get-utc-time',
'/edge-functions/test',
diff --git a/apps/studio/package.json b/apps/studio/package.json
index 8a35b6160e0..8c5954cdad8 100644
--- a/apps/studio/package.json
+++ b/apps/studio/package.json
@@ -25,6 +25,7 @@
"build:graphql-types:watch": "pnpm graphql-codegen --config scripts/codegen.ts --watch"
},
"dependencies": {
+ "@ai-sdk/amazon-bedrock": "^2.2.10",
"@ai-sdk/openai": "^0.0.72",
"@dagrejs/dagre": "^1.0.4",
"@deno/eszip": "0.83.0",
@@ -60,9 +61,11 @@
"@tanstack/react-query-devtools": "4.35.7",
"@tanstack/react-table": "^8.21.3",
"@uidotdev/usehooks": "^2.4.1",
+ "@vercel/functions": "^2.2.2",
"@vitejs/plugin-react": "^4.3.4",
"@zip.js/zip.js": "^2.7.29",
"ai": "^3.4.33",
+ "ai-4": "npm:ai@4",
"ai-commands": "workspace:*",
"awesome-debounce-promise": "^2.1.0",
"common": "workspace:*",
diff --git a/apps/studio/pages/api/ai/temp/bedrock-test.ts b/apps/studio/pages/api/ai/temp/bedrock-test.ts
new file mode 100644
index 00000000000..90d5e9fa2df
--- /dev/null
+++ b/apps/studio/pages/api/ai/temp/bedrock-test.ts
@@ -0,0 +1,70 @@
+import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock'
+import { awsCredentialsProvider } from '@vercel/functions/oidc'
+import { CoreMessage, streamText } from 'ai-4'
+import apiWrapper from 'lib/api/apiWrapper'
+import { NextApiRequest, NextApiResponse } from 'next'
+import { z } from 'zod'
+
+const bedrock = createAmazonBedrock({
+ credentialProvider: awsCredentialsProvider({
+ roleArn: process.env.AWS_BEDROCK_ROLE_ARN!,
+ }),
+})
+
+const messageSchema = z.object({
+ role: z.enum(['user', 'assistant']),
+ content: z.string(),
+})
+
+const requestBodySchema = z.object({
+ messages: z.array(messageSchema),
+})
+
+async function handler(req: NextApiRequest, res: NextApiResponse) {
+ const { method } = req
+
+ switch (method) {
+ case 'POST':
+ return handlePost(req, res)
+ default:
+ res.setHeader('Allow', ['POST'])
+ res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
+ }
+}
+
+async function handlePost(req: NextApiRequest, res: NextApiResponse) {
+ const { data, error: parseError } = requestBodySchema.safeParse(req.body)
+
+ if (parseError) {
+ return res.status(400).json({
+ error: 'Invalid request body',
+ issues: parseError.issues,
+ })
+ }
+
+ const { messages: clientMessages } = data
+
+ const model = bedrock('us.anthropic.claude-sonnet-4-20250514-v1:0')
+ const messages: CoreMessage[] = [
+ {
+ role: 'system',
+ content: 'You are a helpful assistant.',
+ },
+ ...clientMessages,
+ ]
+
+ const result = streamText({
+ model,
+ messages,
+ onError: ({ error }) => {
+ console.error(error)
+ },
+ })
+
+ return result.pipeDataStreamToResponse(res)
+}
+
+const wrapper = (req: NextApiRequest, res: NextApiResponse) =>
+ apiWrapper(req, res, handler, { withAuth: false })
+
+export default wrapper
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8841ae78d96..9de532ea492 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -331,7 +331,7 @@ importers:
'@sentry/nextjs':
specifier: ^9.15.0
'@supabase/supabase-js':
specifier: 'catalog:'
version: 2.49.3
@@ -451,7 +451,7 @@ importers:
nuqs:
specifier: ^1.19.1
openai:
specifier: ^4.20.1
@@ -651,6 +651,9 @@ importers:
apps/studio:
dependencies:
+ '@ai-sdk/amazon-bedrock':
+ specifier: ^2.2.10
+ version: 2.2.10([email protected])
'@ai-sdk/openai':
specifier: ^0.0.72
version: 0.0.72([email protected])
@@ -756,6 +759,9 @@ importers:
'@uidotdev/usehooks':
specifier: ^2.4.1
+ '@vercel/functions':
+ specifier: ^2.2.2
+ version: 2.2.2(@aws-sdk/[email protected])
'@vitejs/plugin-react':
specifier: ^4.3.4
@@ -765,6 +771,9 @@ importers:
ai:
specifier: ^3.4.33
+ ai-4:
+ specifier: npm:ai@4
ai-commands:
specifier: workspace:*
version: link:../../packages/ai-commands
@@ -1110,7 +1119,7 @@ importers:
version: 2.4.11([email protected])
next-router-mock:
specifier: ^0.9.13
postcss:
specifier: ^8.5.3
version: 8.5.3
@@ -1270,7 +1279,7 @@ importers:
'@tanstack/react-start':
specifier: ^1.114.25
'@types/lodash':
specifier: ^4.17.16
version: 4.17.16
@@ -2266,7 +2275,7 @@ importers:
version: link:../api-types
next-router-mock:
specifier: ^0.9.13
tsx:
specifier: ^4.19.3
version: 4.19.3
@@ -2295,6 +2304,12 @@ packages:
resolution: {integrity: sha512-Ff9+ksdQQB3rMncgqDK78uLznstjyfIf2Arnh22pW8kBpLs6rpKDwgnZT46hin5Hl1WzazzK64DOrhSwYpS7bQ==}
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-icLGO7Q0NinnHIPgT+y1QjHVwH4HwV+brWbvM+FfCG2Afpa89PyKa3Ret91kGjZpBgM/xnj1B7K5eM+rRlsXQA==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ zod: ^3.0.0
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-IKsgxIt6KJGkEHyMp975xW5VPmetwhI8g9H6dDmwvemBB41IRQa78YMNttiJqPcgmrZX2QfErOICv1gQvZ1gZg==}
engines: {node: '>=18'}
@@ -2310,10 +2325,20 @@ packages:
zod:
optional: true
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-fqhG+4sCVv8x7nFzYnFo19ryhAa3w096Kmc3hWxMQfW/TubPOmt3A6tYZhl4mUfQWWQMsuSkLrtjlWuXBVSGQA==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ zod: ^3.23.8
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-dQkfBDs2lTYpKM8389oopPdQgIU007GQyCbuPPrV+K6MtSII3HBfE0stUIMXUb44L+LK1t6GXPP7wjSzjO6uKg==}
engines: {node: '>=18'}
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-qZMxYJ0qqX/RfnuIaab+zp8UAeJn/ygXXAffR5I4N0n1IrvA6qBsjc8hXLmBiMV2zoXlifkacF7sEFnYnjBcqg==}
+ engines: {node: '>=18'}
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-GnwbtjW4/4z7MleLiW+TOZC2M29eCg1tOUpuEiYFMmFNZK8mkrqM0PFZMo6UsYeUYMWqEOOcPOU9OQVJMJh7IQ==}
engines: {node: '>=18'}
@@ -2326,6 +2351,16 @@ packages:
zod:
optional: true
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-jK1IZZ22evPZoQW3vlkZ7wvjYGYF+tRBKXtrcolduIkQ/m/sOAVcVeVDUDvh1T91xCnWCdUGCPZg2avZ90mv3g==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ react: ^18 || ^19 || ^19.0.0-rc
+ zod: ^3.23.8
+ peerDependenciesMeta:
+ zod:
+ optional: true
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-96KWTVK+opdFeRubqrgaJXoNiDP89gNxFRWUp0PJOotZW816AbhUf4EnDjBjXTLjXL1n0h8tGSE9sZsRkj9wQQ==}
engines: {node: '>=18'}
@@ -2353,6 +2388,12 @@ packages:
zod:
optional: true
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-3zcwCc8ezzFlwp3ZD15wAPjf2Au4s3vAbKsXQVyhxODHcmu0iyPO2Eua6D/vicq/AUm/BAo60r97O6HU+EI0+w==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ zod: ^3.23.8
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-+ofYlnqdc8c4F6tM0IKF0+7NagZRAiqBJpGDJ+6EYhDW8FHLUP/JFBgu32SjxSxC6IKFZxEnl68ZoP/Z38EMlw==}
engines: {node: '>=18'}
@@ -8663,6 +8704,15 @@ packages:
'@usercentrics/[email protected]':
resolution: {integrity: sha512-/cik01TdeiYUV1+EasK83Ip05TDqmowM5tmWGfRDdaOrneSic5BedBdJHKya4pP2vwiYAtzDYVJe4BwPt2M16g==}
+ '@vercel/[email protected]':
+ resolution: {integrity: sha512-wgtgFwhYAUzS7UOvw44q14FaoRPONEnyoM0JlrjcDkI+kzSu7M8J5Tk5T3Kvv52//8is+HGxVQtaBSiO3G0wbw==}
+ engines: {node: '>= 18'}
+ peerDependencies:
+ '@aws-sdk/credential-provider-web-identity': '*'
+ peerDependenciesMeta:
+ '@aws-sdk/credential-provider-web-identity':
+ optional: true
+
'@vercel/[email protected]':
resolution: {integrity: sha512-A/Si4mrTkQqJ6EXJKv5EYCDQ3NL6nJXxG8VGXePsaiQigsomHYQC9xSpX8qGk7AEZk4b1ssbYIqJ0ISQQ7bfcA==}
engines: {node: '>=18'}
@@ -8937,6 +8987,16 @@ packages:
zod:
optional: true
+ resolution: {integrity: sha512-KUDwlThJ5tr2Vw0A1ZkbDKNME3wzWhuVfAOwIvFUzl1TPVDFAXDFTXio3p+jaKneB+dKNCvFFlolYmmgHttG1g==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ react: ^18 || ^19 || ^19.0.0-rc
+ zod: ^3.23.8
+ peerDependenciesMeta:
+ react:
+ optional: true
+
resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==}
peerDependencies:
@@ -9210,6 +9270,9 @@ packages:
resolution: {integrity: sha512-7q4WPsYiD8Omvi/yHL314DkvsD/lM//Z2/KcU1vWk0xJotiV0GMJTgHTpWl3n90HJqpXKg7qX+VVNs5YbQyPRQ==}
engines: {node: '>=8', npm: '>=5'}
+ resolution: {integrity: sha512-/djoAN709iY65ETD6LKCtyyEI04XIBP5xVvfmNxsEP0uJB5tyaGBztSryRr4HqMStr9R06PisQE7m9zDTXKu6g==}
+
resolution: {integrity: sha512-Xm7bpRXnDSX2YE2YFfBk2FnF0ep6tmG7xPh8iHee8MIcrgq762Nkce856dYtJYLkuIoYZvGfTs/PbZhideTcEg==}
engines: {node: '>=4'}
@@ -10891,7 +10954,6 @@ packages:
resolution: {integrity: sha512-t0q23FIpvHDTtnORW+bDJziGsal5uh9RJTJ1fyH8drd4lICOoXhJ5pLMUZ5C0VQei6dNmwTzzoTRgMkO9JgHEQ==}
peerDependencies:
eslint: '>= 5'
- bundledDependencies: []
resolution: {integrity: sha512-ixmkI62Rbc2/w8Vfxyh1jQRTdRTF52VxwRVHl/ykPAmqG+Nb7/kNn+byLP0LxPgI7zWA16Jt82SybJInmMia3A==}
@@ -17769,6 +17831,11 @@ packages:
peerDependencies:
zod: ^3.23.3
+ resolution: {integrity: sha512-h/z3PKvcTcTetyjl1fkj79MHNEjm+HpD6NXheWjzOekY7kV+lwDYnHw+ivHkijnCSMz1yJaWBD9vu/Fcmk+vEg==}
+ peerDependencies:
+ zod: ^3.24.1
+
resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==}
@@ -17802,6 +17869,15 @@ snapshots:
'@adobe/[email protected]': {}
+ dependencies:
+ '@ai-sdk/provider': 1.1.3
+ '@ai-sdk/provider-utils': 2.2.8([email protected])
+ '@smithy/eventstream-codec': 4.0.4
+ '@smithy/util-utf8': 4.0.0
+ aws4fetch: 1.0.20
+ zod: 3.23.8
+
dependencies:
'@ai-sdk/provider': 0.0.26
@@ -17817,10 +17893,21 @@ snapshots:
optionalDependencies:
zod: 3.23.8
+ dependencies:
+ '@ai-sdk/provider': 1.1.3
+ nanoid: 3.3.8
+ secure-json-parse: 2.7.0
+ zod: 3.23.8
+
'@ai-sdk/[email protected]':
dependencies:
json-schema: 0.4.0
+ '@ai-sdk/[email protected]':
+ dependencies:
+ json-schema: 0.4.0
+
dependencies:
'@ai-sdk/provider-utils': 1.0.22([email protected])
@@ -17831,6 +17918,16 @@ snapshots:
react: 18.3.1
zod: 3.23.8
+ dependencies:
+ '@ai-sdk/provider-utils': 2.2.8([email protected])
+ '@ai-sdk/ui-utils': 1.2.11([email protected])
+ react: 18.3.1
+ swr: 2.2.5([email protected])
+ throttleit: 2.1.0
+ optionalDependencies:
+ zod: 3.23.8
+
dependencies:
'@ai-sdk/provider-utils': 1.0.22([email protected])
@@ -17858,6 +17955,13 @@ snapshots:
optionalDependencies:
zod: 3.23.8
+ dependencies:
+ '@ai-sdk/provider': 1.1.3
+ '@ai-sdk/provider-utils': 2.2.8([email protected])
+ zod: 3.23.8
+ zod-to-json-schema: 3.24.6([email protected])
+
dependencies:
'@ai-sdk/provider-utils': 1.0.22([email protected])
@@ -17902,7 +18006,7 @@ snapshots:
'@aws-crypto/[email protected]':
dependencies:
'@aws-crypto/util': 3.0.0
- '@aws-sdk/types': 3.468.0
+ '@aws-sdk/types': 3.821.0
tslib: 1.14.1
'@aws-crypto/[email protected]':
@@ -17979,7 +18083,7 @@ snapshots:
'@aws-crypto/[email protected]':
dependencies:
- '@aws-sdk/types': 3.468.0
+ '@aws-sdk/types': 3.821.0
'@aws-sdk/util-utf8-browser': 3.259.0
tslib: 1.14.1
@@ -24613,7 +24717,7 @@ snapshots:
- supports-color
- webpack
dependencies:
'@opentelemetry/api': 1.9.0
'@opentelemetry/semantic-conventions': 1.32.0
@@ -25680,7 +25784,7 @@ snapshots:
tiny-invariant: 1.3.3
tiny-warning: 1.0.3
dependencies:
'@tanstack/react-router': 1.114.27([email protected]([email protected]))([email protected])
'@tanstack/router-core': 1.114.25
@@ -25691,7 +25795,7 @@ snapshots:
react-dom: 18.3.1([email protected])
tiny-invariant: 1.3.3
tiny-warning: 1.0.3
transitivePeerDependencies:
- '@azure/app-configuration'
- '@azure/cosmos'
@@ -25735,7 +25839,7 @@ snapshots:
- xml2js
- yaml
dependencies:
'@tanstack/router-core': 1.114.25
@@ -25745,11 +25849,11 @@ snapshots:
'@tanstack/start-server-functions-handler': 1.114.25
import-meta-resolve: 4.1.0
ofetch: 1.4.1
react: 18.3.1
react-dom: 18.3.1([email protected])
zod: 3.24.2
transitivePeerDependencies:
@@ -25827,11 +25931,11 @@ snapshots:
- tsx
- yaml
dependencies:
'@tanstack/router-core': 1.114.25
tiny-invariant: 1.3.3
transitivePeerDependencies:
- '@azure/app-configuration'
- '@azure/cosmos'
@@ -25890,13 +25994,13 @@ snapshots:
tiny-warning: 1.0.3
unctx: 2.4.1
dependencies:
'@tanstack/react-start-server': 1.114.27([email protected]([email protected]))([email protected])
'@tanstack/start-server-functions-handler': 1.114.25
@@ -26047,11 +26151,11 @@ snapshots:
- tsx
- yaml
dependencies:
'@tanstack/router-core': 1.114.25
'@tanstack/start-server-core': 1.114.25
transitivePeerDependencies:
- '@azure/app-configuration'
- '@azure/cosmos'
@@ -26914,6 +27018,10 @@ snapshots:
lz-string: 1.5.0
uuid: 9.0.1
+ '@vercel/[email protected](@aws-sdk/[email protected])':
+ optionalDependencies:
+ '@aws-sdk/credential-provider-web-identity': 3.821.0
+
dependencies:
'@mapbox/node-pre-gyp': 2.0.0([email protected])([email protected])
@@ -27339,6 +27447,18 @@ snapshots:
- solid-js
- vue
+ dependencies:
+ '@ai-sdk/provider': 1.1.3
+ '@ai-sdk/provider-utils': 2.2.8([email protected])
+ '@ai-sdk/react': 1.2.12([email protected])([email protected])
+ '@ai-sdk/ui-utils': 1.2.11([email protected])
+ '@opentelemetry/api': 1.9.0
+ jsondiffpatch: 0.6.0
+ zod: 3.23.8
+ optionalDependencies:
+ react: 18.3.1
+
optionalDependencies:
ajv: 8.12.0
@@ -27648,6 +27768,8 @@ snapshots:
dependencies:
awesome-imperative-promise: 1.0.1
+
@@ -33356,7 +33478,7 @@ snapshots:
dependencies:
js-yaml-loader: 1.2.2
dependencies:
react: 18.3.1
@@ -33404,7 +33526,7 @@ snapshots:
dependencies:
'@cloudflare/kv-asset-handler': 0.4.0
'@netlify/functions': 3.0.4
@@ -33473,7 +33595,7 @@ snapshots:
unenv: 2.0.0-rc.15
unimport: 4.1.2
unplugin-utils: 0.2.4
untyped: 2.0.0
unwasm: 0.3.9
youch: 4.1.0-beta.6
@@ -33693,7 +33815,7 @@ snapshots:
dependencies:
mitt: 3.0.1
@@ -37519,7 +37641,7 @@ snapshots:
acorn: 8.14.1
webpack-virtual-modules: 0.6.2
dependencies:
anymatch: 3.1.3
chokidar: 4.0.3
@@ -37530,6 +37652,7 @@ snapshots:
ofetch: 1.4.1
ufo: 1.5.4
optionalDependencies:
+ aws4fetch: 1.0.20
ioredis: 5.6.0([email protected])
@@ -37752,7 +37875,7 @@ snapshots:
d3-time: 3.1.0
d3-timer: 3.0.1
dependencies:
'@babel/core': 7.26.10([email protected])
'@babel/plugin-syntax-jsx': 7.25.9(@babel/[email protected]([email protected]))
@@ -37774,7 +37897,7 @@ snapshots:
hookable: 5.5.3
http-proxy: 1.18.1
micromatch: 4.0.8
node-fetch-native: 1.6.6
path-to-regexp: 6.3.0
pathe: 1.1.2
@@ -37785,7 +37908,7 @@ snapshots:
ufo: 1.5.4
unctx: 2.4.1
unenv: 1.10.0
zod: 3.23.8
transitivePeerDependencies:
@@ -38373,6 +38496,10 @@ snapshots:
dependencies:
zod: 3.23.8
+ dependencies:
+ zod: 3.23.8
+
diff --git a/turbo.json b/turbo.json
index 4002332fed4..6a883096ddb 100644
--- a/turbo.json
+++ b/turbo.json
@@ -90,6 +90,8 @@
"SENTRY_AUTH_TOKEN",
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
+ "AWS_BEDROCK_REGION",
+ "AWS_BEDROCK_ROLE_ARN",
"FORCE_ASSET_CDN",
"ASSET_CDN_S3_ENDPOINT",
"SITE_NAME",