trpc call that doesn't use prisma

Hi, I need create a trpc endpoint that just calls openAI api. Is it possible to do this in an endpoint with using prisma? What does it look like?
1 Reply
thejessewinton
Same core concept; create your endpoint, do the api call, return your data!
getOpenAI: publicProcedure
.input(z.object({/* your schema */}))
.query(async ({ ctx, input }) => {
const res = await fetch(/* OpenAI Endpoint */)
return await data.json()
}),
getOpenAI: publicProcedure
.input(z.object({/* your schema */}))
.query(async ({ ctx, input }) => {
const res = await fetch(/* OpenAI Endpoint */)
return await data.json()
}),
For more type-safety, if you know the shape of the data you’re getting you should run it through zod.safeParse and return that instead. Typing from my phone, but this should get you started.
Want results from more Discord servers?
Add your server