Hi,
I have a website that used to work using ChatGPT api behind the scenes, however today I am receiving this error (I have 0/10 £ used this month, i definitely have quoata):
error: {
message: 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.',
type: 'insufficient_quota',
param: null,
code: 'insufficient_quota'
},
This happened yesterday and today, yet I don’t see anything on the forums indicating others are having this issue.
I have stored my code implementation here incase something has changed since:
import OpenAI from 'openai';
import { OpenAIStream, StreamingTextResponse } from 'ai';
// Optional, but recommended: run on the edge runtime.
// See https://vercel.com/docs/concepts/functions/edge-functions
export const runtime = 'edge';
const openai = new OpenAI({
// Safely handle potential undefined value
apiKey: process.env.OPENAI_API_KEY || '',
});
export async function POST(req: Request): Promise<StreamingTextResponse> {
// Extract the `messages` from the body of the request
const { messages } = await req.json();
// Request the OpenAI API for the response based on the prompt
const response = await openai.chat.completions.create({
model: 'gpt-4-1106-preview',
stream: true,
messages: messages,
});
// Convert the response into a friendly text-stream
const stream = OpenAIStream(response);
// Respond with the stream
return new StreamingTextResponse(stream);
}