Getting a 403 Forbidden error when calling Vercel AI Gateway
Unanswered
Braque de l'Ariège posted this in #help-forum
Braque de l'AriègeOP
Error [GatewayInternalServerError]: Forbidden.
statusCode: 403
type: 'internal_server_error'
I’m using useChat on the frontend with an /api/chat route.
When sending a message, the request fails with a 403 Forbidden from AI Gateway.
statusCode: 403
type: 'internal_server_error'
I’m using useChat on the frontend with an /api/chat route.
When sending a message, the request fails with a 403 Forbidden from AI Gateway.
18 Replies
Braque de l'AriègeOP
thats what the server console shows, i configured everything the same way the docs show it and i get this error
above that, there should be more logs
Braque de l'AriègeOP
I only get this message
Error [GatewayInternalServerError]: Forbidden.
at ignore-listed frames {
statusCode: 403,
generationId: undefined,
type: 'internal_server_error',
[cause]: Error [AI_APICallError]: [object Object]
at ignore-listed frames {
cause: undefined,
url: 'https://ai-gateway.vercel.sh/v3/ai/language-model',
requestBodyValues: {
maxOutputTokens: undefined,
temperature: undefined,
topP: undefined,
topK: undefined,
presencePenalty: undefined,
frequencyPenalty: undefined,
stopSequences: undefined,
seed: undefined,
tools: [Array],
toolChoice: [Object],
responseFormat: undefined,
prompt: [Array],
providerOptions: undefined,
headers: undefined,
includeRawChunks: false
},
statusCode: 403
Error [GatewayInternalServerError]: Forbidden.
at ignore-listed frames {
statusCode: 403,
generationId: undefined,
type: 'internal_server_error',
[cause]: Error [AI_APICallError]: [object Object]
at ignore-listed frames {
cause: undefined,
url: 'https://ai-gateway.vercel.sh/v3/ai/language-model',
requestBodyValues: {
maxOutputTokens: undefined,
temperature: undefined,
topP: undefined,
topK: undefined,
presencePenalty: undefined,
frequencyPenalty: undefined,
stopSequences: undefined,
seed: undefined,
tools: [Array],
toolChoice: [Object],
responseFormat: undefined,
prompt: [Array],
providerOptions: undefined,
headers: undefined,
includeRawChunks: false
},
statusCode: 403
have you put your AI gateway api key? https://vercel.com/docs/ai-gateway/getting-started/text
but wait, its a 403 err
can you share your code
Braque de l'AriègeOP
In frontend i have
when giving input message and submitting it sends a request to /api/chat route
const { messages, sendMessage, status } = useChat();
const handleSend = async () => {
if (!input.trim()) return;
setInput("");
await sendMessage({ text: input });
};<Input
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyPress={(e) => e.key === "Enter" && handleSend()}
placeholder="Plan, search, build anything..."
className="flex-1 bg-white border-gray-300 text-gray-900 placeholder:text-gray-400"
/>when giving input message and submitting it sends a request to /api/chat route
export async function POST(req: NextRequest) {
const { messages }: { messages: UIMessage[] } = await req.json();
return createAgentUIStreamResponse({
agent: agent,
uiMessages: messages,
});
}agent looks like this:
export const agent = new ToolLoopAgent({
model: "openai/gpt-4o",
stopWhen: stepCountIs(5),
tools: {
addClient: tool({
description: "Create",
inputSchema: z.object({
createClientInput: z.object({
name: z.string().describe("name"),
email: z.string().email().describe("email"),
notes: z
.string()
.optional()
.describe("notes that can be added"),
}),
}) as FlexibleSchema,
execute: async ({
createClientInput,
}: {
createClientInput: CreateClientInput;
}) => {
const res = await add(createInput);
return {
kind: "updated",
client: res,
message: "created successfully",
};
},
})Braque de l'AriègeOP
I checked that API Key is correct and it also showed in vercel that the key is being used so the api key is correct
Braque de l'AriègeOP
Also when trying to add my own openai key to Bring your own key in vercel dashboard i see this
But when i try to use openai api directly it works
@Braque de l'Ariège But when i try to use openai api directly it works
For now, you can use it directly
but do you prefer to use BYOK in vercel Dashboard?
Braque de l'AriègeOP
i tried to put openai key in BYOK in vercel dashboard and when testing it i get this message of connection failed: Forbidden
@Braque de l'Ariège Also when trying to add my own openai key to Bring your own key in vercel dashboard i see this
you might need to contact vercel support since you are getting it even in vercel dashboar
Braque de l'AriègeOP
does vercel have support
umm obviously