A simple Node.js application demonstrating the OpenAI API with a basic text-generation example using the Responses API (client.responses.create).
- Node.js 22 or newer (required by the
openaiv7 SDK) - An OpenAI API key
- Clone or download this repository
- Install dependencies:
npm install - Configure your OpenAI API key:
- Open the
.envfile - Replace
your_openai_api_key_herewith your actual OpenAI API key
OPENAI_API_KEY=your_actual_api_key - Open the
Run the example script:
npm start
This will execute a simple prompt asking for a one-sentence bedtime story about a unicorn using gpt-6-luna.
The script demonstrates:
- Loading environment variables with dotenv
- Initializing the OpenAI client
- Using system prompts to guide the AI's behavior
- Setting the reasoning effort (
reasoning.effort) to trade quality for speed and cost - Error handling for API requests
You can modify the openai.js file to:
- Change the prompt
- Adjust the reasoning effort (
none,low,medium,high);temperature(0-2) only works with effortnone - Try different models
- Customize the system prompt
- Add more messages to the conversation