OpenAI Enterprise for developers
Quick answer
OpenAI Enterprise provides developers with dedicated API keys, enhanced security, and scalable infrastructure for production AI applications. Use the standard
OpenAI SDK with your enterprise API key set in os.environ["OPENAI_API_KEY"] to access enterprise features seamlessly.PREREQUISITES
Python 3.8+OpenAI Enterprise API keypip install openai>=1.0
Setup
Install the official openai Python package and set your OpenAI Enterprise API key as an environment variable for secure authentication.
pip install openai>=1.0 output
Collecting openai Downloading openai-1.x.x-py3-none-any.whl (xx kB) Installing collected packages: openai Successfully installed openai-1.x.x
Step by step
Use the OpenAI SDK to call the API with your enterprise key. This example sends a chat completion request to gpt-4o, the recommended model for enterprise workloads.
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello from OpenAI Enterprise!"}]
)
print(response.choices[0].message.content) output
Hello from OpenAI Enterprise! How can I assist you today?
Common variations
- Use
gpt-4o-minifor lower latency and cost. - Enable streaming by adding
stream=Truetochat.completions.create. - Use async calls with
asyncioandawaitfor concurrency.
import os
import asyncio
from openai import OpenAI
async def main():
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
stream = await client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Stream a response."}],
stream=True
)
async for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)
asyncio.run(main()) output
Streaming response text appears here in real time...
Troubleshooting
- If you get
401 Unauthorized, verify yourOPENAI_API_KEYis correct and has enterprise access. - For
429 Rate Limiterrors, check your enterprise quota and request an increase if needed. - Ensure your network allows outbound HTTPS requests to
api.openai.com.
Key Takeaways
- Use the official
openaiSDK with your enterprise API key for seamless integration. - Enterprise keys provide enhanced security, higher rate limits, and dedicated support.
- Streaming and async calls improve responsiveness for production applications.