Open ai api not generating response for my twitter bot

97 Views Asked by At

I am creating a twitter bot in node js, that uses openai api to create a text and post it on twitter, but it is failing to do so showing the error:

Error generating topic: { 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' } } Error tweeting: Error: Could not authenticate you.

and i have 0% usage in the dashboard

here is the code and i have removed keys from here:

const Twit = require('twit');
const axios = require('axios');

// Twitter API Configuration
const twitterConfig = {
  consumer_key: '',
  consumer_secret: '',`your text`
  access_token: '',
  access_token_secret: '',
};

const twitter = new Twit(twitterConfig);

// OpenAI API configuration
const openaiApiKey = '';
const openaiApiUrl = 'https://api.openai.com/v1/engines/text-davinci-003/completions';

// Function to generate a software development topic using ChatGPT
async function generateTopic() {
  try {
    const response = await axios.post(
      openaiApiUrl,
      {
        prompt: 'Generate a unique tweet about software development topic',
        max_tokens: 60,
      },
      {
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${openaiApiKey}`,
        },
      }
    );

    return response.data.choices[0].text.trim();
  } catch (error) {
    console.error('Error generating topic:', error.response ? error.response.data : error.message);
    return 'An error occurred while generating the topic.';
  }
}

// Function to tweet a topic
function tweetTopic(topic) {
  twitter.post(
    'statuses/update',
    { status: topic },
    (err, data, response) => {
      if (err) {
        console.error('Error tweeting:', err);
      } else {
        console.log('Tweeted:', data.text);
      }
    }
  );
}

// Tweet a new topic every hour
setInterval(async () => {
  const topic = await generateTopic();
  tweetTopic(topic);
}, 1 * 60 * 1000); 

0

There are 0 best solutions below