-1

I'm currently trying to make a dashboard in excel that allows me to utilize Chat GPT for answering basic excel questions for co-workers. The problem it keeps returning says that I'm out of usage with API Key that I have from Chat GPT API, but I do have a paid account with them. I based this office script off the video link listed below. I did change the code from what the video had available due to the errors that kept occurring in excel. I've removed my API Key also. Do you guys have any thoughts on what I should do?

Video Link:https://youtu.be/kQPUWryXwag

Code:async function main(workbook: ExcelScript.Workbook) {
  const apiKey: string = "API Key Insert";
    const endpoint: string = "https://api.openai.com/v1/completions";

    const sheet: ExcelScript.Worksheet = workbook.getWorksheet("Prompt");
    const mytext: string = sheet.getRange("B2").getValue();

    const result: ExcelScript.Worksheet = workbook.getWorksheet("Result");
    result.getRange("A1:D1000").clear();
    sheet.getRange("B3").setValue(" ");

    const model: string = "text-davinci-002";
    const prompt: string = mytext.toString();

    const headers: Headers = new Headers();
    headers.append("Content-Type", "application/json");
    headers.append("Authorization", `Bearer ${apiKey}`);

    const body: string = JSON.stringify({
        model: model,
        prompt: prompt,
        max_tokens: 1024,
        n: 1,
        temperature: 0.5,
    });

    console.log("Request body:", body);

    const response: Response = await fetch(endpoint, {
        method: "POST",
        headers: headers,
        body: body,
    });

    const jsonResponse: { choices: { text: string | boolean | number }[] } = await response.json();
    console.log("Response:", jsonResponse);

    const json: { choices: { text: string | boolean | number }[] } = jsonResponse;

    let text: string | boolean | number = "";

    if (json.choices && json.choices.length > 0) {
        text = json.choices[0].text;
    }

    console.log("Generated text:", text);

    const output: ExcelScript.Range = sheet.getRange("B4");
    output.setValue(text);

    const cell: ExcelScript.Range = sheet.getRange("B4");
    const arr: string[] = cell.getValue().toString().split("\n");
    const newcell: ExcelScript.Range = result.getRange("A1");
    var offset: number = 0;

    for (let i = 0; i < arr.length; i++) {
        if (arr[i].length > 0) {
            newcell.getOffsetRange(offset, 0).setValue(arr[i]);
            offset++;
        }
    }

    if (offset > 1) {
        sheet.getRange("B3").setValue("Check 'Result' sheet to get answers separated by multiple rows");
    }
}

Error Message:

Request body: {"model":"text-davinci-002","prompt":"What is the biggest building in america?","max_tokens":1024,"n":1,"temperature":0.5} Response: {error: Object} error: Object message: "You exceeded your current quota, please check your plan and billing details." type: "insufficient_quota" param: null code: null Generated text:

Trouble Shooting: I've tried using new API Keys. I bought a paid account with Chat GPT API. I honestly thought that if I got the paid account that the error message would go away when I created a new API Key.

  • 2
    Does this answer your question? [OpenAI ChatGPT (GPT-3.5) API error 429: "You exceeded your current quota, please check your plan and billing details"](https://stackoverflow.com/questions/75898276/openai-chatgpt-gpt-3-5-api-error-429-you-exceeded-your-current-quota-please) – rozsazoltan Jun 22 '23 at 16:51

1 Answers1

0

The error suggests that you have consumed your quota. So if you're on a free plan, you'll need to upgrade to a paid plan. If you're already on a paid plan, you'll need to upgrade to increase your limits.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253