Help with chatgpt + telegram

I have a problem in my code, it keeps giving me this error and I don’t know how to solve it, I would like your help

from openai import OpenAI
import telebot

client = OpenAI(
bot = telebot.TeleBot(“token”, parse_mode=None)

@bot.message_handler(commands=[‘start’, ‘help’])
def send_welcome(message):
bot.reply_to(message, “Howdy, how are you doing?”)

@bot.message_handler(func=lambda message: True)
def telegram_bot_message(message):

message_text = message.text.lower()

chat_completion =
            "role": "user",
            "content": message_text,


model_response = chat_completion['choices'][0]['message']['content']

# Send the response back to the user
bot.reply_to(message, model_response)


error that keeps giving is this:
model_response = chat_completion[‘choices’][0][‘message’][‘content’]
TypeError: ‘ChatCompletion’ object is not subscriptable

You are trying to access key of a dictionary, but chat_completion is not one. You either need to convert it to a dictionary or access its values using object notation.

how would it be? I’m new, could you show me an example?

model_response = chat_completion.model_dump_json()['choices'][0]['message']['content']