OpenAI
Overview
OpenAI provides industry-leading language models including GPT-6 and the GPT-5.x family. Emergent supports OpenAI models out of the box, allowing you to build applications powered by these models through simple chat interactions.
You can use OpenAI models in two ways:
- Automatically via The Universal LLM Key - Emergent provides access without requiring your own API key
- With your own API key - Connect your OpenAI account for direct billing and usage tracking
Using OpenAI with the Universal LLM Key
The simplest way to get started is using Emergent's Universal LLM Key, which provides immediate access to OpenAI models without any configuration.
Note
The Universal LLM Key is included with your Emergent account and supports multiple AI providers including OpenAI. Your usage is metered as part of your Emergent subscription.
When you describe your app in chat, Emergent agents automatically use OpenAI models (or other supported providers) through the Universal LLM Key. No additional setup is required - just start building.
Connecting Your Own OpenAI API Key
The preferred approach is the Universal LLM Key . However, if you want to bring your own OpenAI API key, you can provide your own key when Emergent asks for your OpenAI credentials.
Visit platform.openai.com/api-keys and sign in to your OpenAI account. Click Create new secret key, give it a descriptive name, and copy the key immediately (it won't be shown again).
Warning
Never commit your API key to version control or share it publicly. Treat it like a password.
Building AI Features with OpenAI
When describing your app in chat, you can reference OpenAI capabilities directly:
Simply describe what you want in natural language:
"Add a chatbot that uses GPT-5.4 to answer customer questions about our products"
"Create a content summarizer using GPT-5.x"
"Build an AI writing assistant with GPT-6 for generating blog posts"
Emergent agents will generate the appropriate code to integrate OpenAI models. Your application will include properly structured API calls with error handling, streaming support, and token management.
The generated code handles:
- Authentication and API key management
- Request formatting and model parameters
- Response parsing and streaming
- Rate limiting and error recovery
Best Practices
Choose the right model
Use more capable models in the GPT-6 / GPT-5.x lineup for complex reasoning and creativity. Use lighter models for speed and cost efficiency on simpler tasks.
Monitor usage
Track your OpenAI API usage in the OpenAI dashboard to manage costs. Set usage limits if needed.
Implement caching
For repeated queries, describe caching requirements to Emergent agents to reduce API calls and costs.
Handle rate limits
Describe retry logic and graceful degradation when explaining features that make frequent API calls.
Cost Optimization
When building AI-powered features, consider these strategies to optimize OpenAI costs:
- Use appropriate models - Match model capability to task complexity
- Implement prompt caching - Cache responses for identical or similar queries
- Limit context length - Only include necessary context in prompts
- Use streaming - Stream responses for better user experience without extra cost
- Set max tokens - Configure maximum response lengths to prevent runaway costs
Tip
When describing AI features to Emergent, mention cost optimization requirements explicitly: "Build this feature to minimize token usage" or "Use a cost-efficient model for this task".
Troubleshooting
| Issue | Solution |
|---|---|
| API key not working or showing authentication errors | Verify that: - Your API key was copied correctly without extra spaces - Your OpenAI account has billing enabled and sufficient credits - The API key has not been revoked in your OpenAI dashboard - You've saved the configuration in Emergent after pasting the key |
| Rate limit errors | OpenAI enforces rate limits based on your account tier. If you encounter rate limit errors: - Implement exponential backoff and retry logic (describe this to Emergent agents) - Upgrade your OpenAI account tier for higher limits - Reduce request frequency in your application logic |
| High costs or unexpected billing | Review your OpenAI usage dashboard to identify expensive operations: - Check if prompts are longer than necessary - Verify you're using the intended model - Look for API calls in loops or high-frequency events - Set up usage alerts in your OpenAI account |
| Model not available or deprecated warnings | OpenAI occasionally deprecates older models. If you see deprecation warnings: - Update your model configuration to use current model versions - Describe the required change to Emergent agents: "Update to use the latest GPT-5.x model" - Test thoroughly after model changes as behavior may differ slightly |

