Pre-release
This release is a pre-release and may not be stable for production use.
elizaOS OpenAI Plugin (Python)
A type-safe async Python client for OpenAI APIs, designed for use with elizaOS.
Features
- 🔒 Strong typing with Pydantic validation
- ⚡ Async-first using httpx
- 🎯 Fail-fast error handling - no silent failures
- 📝 Full API coverage:
- Text generation (GPT-4, GPT-4o, etc.)
- Embeddings (text-embedding-3-small, etc.)
- Image generation (DALL-E)
- Image description (GPT-4 Vision)
- Audio transcription (Whisper)
- Text-to-speech
- Tokenization (tiktoken)
Installation
pip install elizaos-plugin-openai
Quick Start
import asyncio
from elizaos_plugin_openai import OpenAIPlugin
async def main():
# Create plugin (uses OPENAI_API_KEY env var by default)
async with OpenAIPlugin() as plugin:
# Generate text
response = await plugin.generate_text_large(
"Explain quantum computing in 2 sentences."
)
print(response)
# Create embedding
embedding = await plugin.create_embedding("Hello, world!")
print(f"Embedding dimensions: {len(embedding)}")
# Describe an image
description = await plugin.describe_image(
"https://example.com/image.jpg"
)
print(f"Title: {description.title}")
print(f"Description: {description.description}")
asyncio.run(main())
Configuration
from elizaos_plugin_openai import OpenAIPlugin
plugin = OpenAIPlugin(
api_key="sk-...", # Or use OPENAI_API_KEY env var
base_url="https://api.openai.com/v1",
small_model="gpt-5-mini",
large_model="gpt-5",
embedding_model="text-embedding-3-small",
embedding_dimensions=1536,
)
Streaming
async with OpenAIPlugin() as plugin:
async for chunk in plugin.stream_text("Tell me a story..."):
print(chunk, end="", flush=True)
Tokenization
from elizaos_plugin_openai import tokenize, detokenize, count_tokens
# Count tokens
count = count_tokens("Hello, world!", model="gpt-5")
print(f"Token count: {count}")
# Tokenize and detokenize
tokens = tokenize("Hello, world!", model="gpt-5")
text = detokenize(tokens, model="gpt-5")
Error Handling
All API errors are raised as OpenAIClientError:
from elizaos_plugin_openai import OpenAIPlugin, OpenAIClientError
async with OpenAIPlugin() as plugin:
try:
result = await plugin.generate_text_large("...")
except OpenAIClientError as e:
print(f"API error ({e.status_code}): {e}")
License
MIT
Metadata
Release files for elizaos-plugin-openai 2.0.0a5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| elizaos_plugin_openai-2.0.0a5.tar.gz | 16.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| elizaos_plugin_openai-2.0.0a5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.3 kB
Release files / elizaos_plugin_openai-2.0.0a5.tar.gz
| Download URL | elizaos_plugin_openai-2.0.0a5.tar.gz |
|---|---|
| Size | 16.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba2cbc5b1252e20041c44602cc69e73084be819b7ecb4fd8153f0eac16308459
|
|
BLAKE2b-256 checksum How to use checksums |
b222b8765e5e5441f140f19e8955dd6ec3607a2c3bda6f891b3e0a71863a222e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Release files / elizaos_plugin_openai-2.0.0a5-py3-none-any.whl
| Download URL | elizaos_plugin_openai-2.0.0a5-py3-none-any.whl |
|---|---|
| Size | 17.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d893593d638f6594ff39a42fde65ba76c251d2a57b9ff8c92eaec315d834e6e
|
|
BLAKE2b-256 checksum How to use checksums |
62aacde4e5896c20102cb13eb85114fabc26c9f2ade31e85ba3025af74c2ff73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|