Changes for GPT 5 in Build AI-Powered Apps

I have noticed that OpenAI has made some breaking changes to its API with the introduction of GPT 5. These are not yet documented.
For example, if you use model: ‘gpt-5-nano’ at the OpenAi client, you must delete the ‘temperature’ parameter, otherwise an error will occur. Changes must be made in the client.ts and in the services layer of the course code.

Typical AI, the course is only a few weeks old and something has already changed again :wink:

2 Likes

Hi horst, I think it’s part of the way, I worked with gpt-4o-mini almost all the course without problem, I think It’s gonna be situations that we should to learn to handle.

At
2.1- Building the Chat API (6:26)
The API has totally changed, this does not currently works:

import express from 'express';
import type { Request, Response } from 'express';
import dotenv from 'dotenv';
import OpenAI from 'openai';
import client from 'openai';

dotenv.config();

const openai = new OpenAI({
   apiKey: process.env.OPENAI_API_KEY,
});

const app = express();
app.use(express.json());
const port = process.env.PORT || 3000;

app.get('/', (req: Request, res: Response) => {
   // res.send(process.env.OPENAI_API_KEY);
   res.send('Hello World!');
});

app.get('/api/hello', (req: Request, res: Response) => {
   // res.send(process.env.OPENAI_API_KEY);
   res.json({ message: 'Hello World!' });
});

app.post('/api/chat', async (req: Request, res: Response) => {
   const { prompt } = req.body;

   const response = await client.responses.create({
      model: 'gpt-4.0-mini',
      input: prompt,
      temperature: 0.2,
      max_output_tokens: 100,
   });

   res.json({ message: response.output_text }); //{ message: response.choices[0].message
});

app.listen(port, () => {
   console.log(`Server is running at http://localhost:${port}`);
});

At the

   client.responses.create({

You will get a

Property 'responses' does not exist on type 'typeof OpenAI'. Did you mean 'Responses'?ts(2551)

To fix the problem, I modified
packages\server\index.ts
as follows:

import express from 'express';
import type { Request, Response } from 'express';
import dotenv from 'dotenv';
import OpenAI from 'openai';

dotenv.config();

const openai = new OpenAI({
   apiKey: process.env.OPENAI_API_KEY,
});

const app = express();
app.use(express.json());
const port = process.env.PORT || 3000;

app.get('/', (req: Request, res: Response) => {
   // res.send(process.env.OPENAI_API_KEY);
   res.send('Hello World!');
});

app.get('/api/hello', (req: Request, res: Response) => {
   // res.send(process.env.OPENAI_API_KEY);
   res.json({ message: 'Hello World!' });
});

app.post('/api/chat', async (req: Request, res: Response) => {
   try {
      const { prompt } = req.body;

      if (!prompt) {
         return res.status(400).json({ error: 'Prompt is required' });
      }

      const response = await openai.chat.completions.create({
         model: 'gpt-4o-mini',
         messages: [
            {
               role: 'user',
               content: prompt,
            },
         ],
         temperature: 0.2,
         max_tokens: 100,
      });

      const content = response.choices[0]?.message?.content;
      res.json({ message: content || 'No response generated' });
   } catch (error) {
      console.error('OpenAI API error:', error);
      res.status(500).json({ error: 'Failed to generate response' });
   }
});

app.listen(port, () => {
   console.log(`Server is running at http://localhost:${port}`);
});

1 Like