#Code
1 messages · Page 1 of 1 (latest)
Hi @opal moat. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Certainly! Here is example code for making a basic text generation request to OpenAI's API using the official JavaScript SDK. This code will prompt the model to write a one-sentence bedtime story about a unicorn:
import OpenAI from "openai";
const client = new OpenAI();
const response = await client.responses.create({
model: "gpt-5",
input: "Write a one-sentence bedtime story about a unicorn."
});
console.log(response.output_text);
To run this code:
- Install the SDK with
npm install openai. - Save the code in a file (e.g.,
example.mjs). - Set your
OPENAI_API_KEYas an environment variable. - Run the file with
node example.mjs.
This will print the model's response to your console. For more details, see the OpenAI Developer Quickstart.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@opal moat Kapa.ai is still learning and improving, please let me know how I did by reacting below.