OpenAI Enterprise custom models
Quick answer
Use the OpenAI Python SDK with your Enterprise API key to call custom models by specifying the model name in client.chat.completions.create. Custom models are accessed like standard models but require your Enterprise account and API key.
PREREQUISITES
Python 3.8+OpenAI Enterprise API keypip install openai>=1.0
Setup
Install the official OpenAI Python SDK and set your Enterprise API key as an environment variable.
pip install openai>=1.0 output
Collecting openai Downloading openai-1.x.x-py3-none-any.whl Installing collected packages: openai Successfully installed openai-1.x.x
Step by step
Use the OpenAI SDK to call your Enterprise custom model by specifying its exact model name. Replace YOUR_ENTERPRISE_MODEL with your custom model ID.
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.chat.completions.create(
model="YOUR_ENTERPRISE_MODEL",
messages=[{"role": "user", "content": "Explain RAG in simple terms."}]
)
print(response.choices[0].message.content) output
Retrieval-Augmented Generation (RAG) is a technique that combines retrieval of relevant documents with generation of answers, improving accuracy and context.
Common variations
You can use async calls, streaming, or switch between different Enterprise custom models by changing the model parameter. Streaming allows partial token output for faster response.
import os
import asyncio
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
async def main():
stream = await client.chat.completions.create(
model="YOUR_ENTERPRISE_MODEL",
messages=[{"role": "user", "content": "Summarize AI trends."}],
stream=True
)
async for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)
asyncio.run(main()) output
AI trends include increased adoption of generative models, improved multimodal capabilities, and wider enterprise integration.
Troubleshooting
- If you get
401 Unauthorized, verify your Enterprise API key is set correctly inOPENAI_API_KEY. - If
model not founderror occurs, confirm your custom model name is correct and accessible in your Enterprise account. - For rate limits, check your Enterprise quota and usage dashboard.
Key Takeaways
- Use the OpenAI Python SDK with your Enterprise API key to access custom models by specifying their model names.
- Custom models behave like standard OpenAI models but require Enterprise account permissions.
- Streaming and async calls improve responsiveness and flexibility with Enterprise custom models.