Skip to main content

elizaOS OpenAI Plugin - OpenAI API integration for text, image, audio, and embeddings

Project description

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

Project details


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.0a4.tar.gz (16.4 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.0a4-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for elizaos_plugin_openai-2.0.0a4.tar.gz
Algorithm Hash digest
SHA256 a565871702a7c885c9b979380683a2493712521083603158f2c13b2cd52f999b
MD5 631b9544f5db4256e5b87ed181e13633
BLAKE2b-256 750fb1c6c16cf35dc80f0a9d5c6d1a537137571c02e1d7de9ddcd7f66e5f65ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for elizaos_plugin_openai-2.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 83bc2917e2763436963eef596fd646906aa197ec6cd36acecd5cbb9e644fb4a0
MD5 256e86c1a6e213b91e88b9bdc85104a2
BLAKE2b-256 afc1a8e6bd4f836d399d300ab6d6ed5b9fa081b3a63dc0e29175f1aa3740f1f7

See more details on using hashes here.

Supported by

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