Prompt engineering - OpenAI API
This guide shares strategies and tactics for getting better results from large language models (sometimes referred to as GPT models) like GPT-4. The methods described here can sometimes be deployed in combination for greater effect. We encourage experimentation to find the methods that work best for you. Some of the examples demonstrated here currently work only with our most capable model, gpt-4. In general, if you find that a model fails at a task and a more capable model is available, it's often worth trying again with the more capable model. You can also explore example prompts which showcase what our models are capable of: These models can’t read your mind. If outputs are too long, ask for brief replies. If outputs are too simple, ask for expert-level writing. If you dislike the format, demonstrate the format you’d like to see. The less the model has to guess at what you want, the more likely you’ll get it. Tactics: Language models can confidently invent fake answers, especially w
With the OpenAI API, you can use a large language model to generate text from a prompt, as you might using ChatGPT . Models can generate almost any kind of text response—like code, mathematical equations, structured JSON data, or human-like prose. Here’s a simple example using the Responses API . Generate text from a simple prompt javascript 1 2 3 4 5 6 7 8 9 import OpenAI from "openai" ; const client = new OpenAI(); const response = await client.responses.create({ model : "gpt-5.5" , input : "Write a one-sentence bedtime story about a unicorn." }); console .log(response.output_text); 1 2 3 4
saved by
related reading
- GitHub - brexhq/prompt-engineering: Tips and tricks for working with Large Language Models like OpenAI's GPT-4.github.com
- Text generation | OpenAI APIplatform.openai.com
- The Shape of AI | UX Patterns for Artificial Intelligence Designshapeof.ai
- Prompt generation | OpenAI APIplatform.openai.com
- Prompting best practicesdocs.anthropic.com
- Cookbookcookbook.openai.com
- GitHub - x1xhlol/system-prompts-and-models-of-ai-tools: FULL Augment Code, Claude Code, Cluely, CodeBuddy, Comet, Cursor, Devin AI, Junie, Kiro, Leap.new, Lovable, Manus, NotionAI, Orchids.app, Perplexity, Poke, Qoder, Replit, Same.dev, Trae, Traycer AI, VSCode Agent, Warp.dev, Windsurf, Xcode, Z.ai Code, Dia & v0. (And other Open Sourced) System Prompts, Internal Tools & AI Modelsgithub.com
- OpenAI | Research & Deploymentopenai.com
- ChatGPT-4 Few Shot Promptingw3schools.com
- GitHub - f/prompts.chat: f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.github.com
- API Overview | OpenAI API Referenceplatform.openai.com
- PromptLayer — Prompt Management, Evals & Observabilitypromptlayer.com