My script stopped working after OpenAI switched to the new Responses API How do I migrate from ChatCompletion

0 votes
May 11 in Generative AI by gaurav
• 24,180 points
44 views

1 answer to this question.

0 votes

The responses API is quite different from old.completions
The old version had
from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(

    model="gpt-4o",

    messages=[

        {"role": "system", "content": "You are a helpful assistant."},

        {"role": "user", "content": "Hello!"}

    ]

)

print(response.choices[0].message.content)
The new version is
from openai import OpenAI

client = OpenAI()

response = client.responses.create(

    model="gpt-4o",

    instructions="You are a helpful assistant.",  # replaces system message

    input="Hello!"  # replaces messages array for simple cases

)

print(response.output_text)

So the basic difference is
1. System inputs : Instructions parameter , this is not a message array .
2. Message -input : for single turn calls , it accepts a single plain array , for multiturn , it accepts arrays similar to before .
3. Response shape changed

  • Old: response.choices[0].message.content

  • New: response.output_text (for simple text) or response.output[0].content[0].text . 



 

answered May 12 by anonymous
• 740 points

Related Questions In Generative AI

0 votes
1 answer
0 votes
1 answer

How do I measure the semantic consistency of outputs from a text-to-text model?

To measure the semantic consistency of outputs from ...READ MORE

answered Jan 15, 2025 in Generative AI by techgil daka
818 views
0 votes
1 answer

How can I optimize Express middleware to handle large payloads from the Google Generative AI API?

Optimizing Express middleware for handling large payloads ...READ MORE

answered Mar 17, 2025 in Generative AI by rupa
722 views
0 votes
1 answer

My Selenium script stopped logging into Kaggle after the CAPTCHA update. How can I handle this?

So basically kaggle strengthened its bot and ...READ MORE

answered May 12 in Generative AI by anonymous
• 740 points
50 views
0 votes
1 answer

My LangChain app stopped working after upgrading to v0.2. What changed in agent execution?

The v0.2 upgrade broke a lot of ...READ MORE

answered May 12 in Generative AI by anonymous
• 740 points
42 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP