Skip to main content
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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elizaos_plugin_openai-2.0.0a5.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elizaos_plugin_openai-2.0.0a5-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file elizaos_plugin_openai-2.0.0a5.tar.gz.

File metadata

  • Download URL: elizaos_plugin_openai-2.0.0a5.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for elizaos_plugin_openai-2.0.0a5.tar.gz
Algorithm Hash digest
SHA256 ba2cbc5b1252e20041c44602cc69e73084be819b7ecb4fd8153f0eac16308459
MD5 bea3d34d78a49635baadfd48a07c29d2
BLAKE2b-256 b222b8765e5e5441f140f19e8955dd6ec3607a2c3bda6f891b3e0a71863a222e

See more details on using hashes here.

File details

Details for the file elizaos_plugin_openai-2.0.0a5-py3-none-any.whl.

File metadata

File hashes

Hashes for elizaos_plugin_openai-2.0.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 6d893593d638f6594ff39a42fde65ba76c251d2a57b9ff8c92eaec315d834e6e
MD5 e886ed143d30d0395fabc3c297b2a1b6
BLAKE2b-256 62aacde4e5896c20102cb13eb85114fabc26c9f2ade31e85ba3025af74c2ff73

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.0a5 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page