Skip to main content

OpenAI Image Generation Tool

This tool allows Agents to generate images using OpenAI's DALL-E model. To see more and get started, visit https://openai.com/blog/dall-e/

Usage

This tool has a more extensive example usage documented in a Jupyter notebook here.

Usage with Agent

from llama_index.tools.openai import OpenAIImageGenerationToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

image_generation_tool = OpenAIImageGenerationToolSpec(
    api_key=os.environ["OPENAI_API_KEY"]
)

agent = FunctionAgent(
    tools=[*image_generation_tool.to_tool_list()],
    llm=OpenAI(model="gpt-4.1"),
)

print(
    await agent.run(
        "A pink and blue llama in a black background with the output"
    )
)

Usage directly

from llama_index.tools.openai import OpenAIImageGenerationToolSpec

image_generation_tool = OpenAIImageGenerationToolSpec(
    api_key=os.environ["OPENAI_API_KEY"]
)

image_data = image_generation_tool.image_generation(
    text="A pink and blue llama with a black background",
    response_format="b64_json",
)

image_bytes = base64.b64decode(image_data)

img = Image.open(BytesIO(image_bytes))

display(img)

image_generation: Takes an text input and generates an image

This loader is designed to be used as a way to load data as a Tool in a Agent.

Download files

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

Source Distribution

Built Distribution

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

File details

Details for the file llama_index_tools_openai_image_generation-0.7.0.tar.gz.

File metadata

  • Download URL: llama_index_tools_openai_image_generation-0.7.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_openai_image_generation-0.7.0.tar.gz
Algorithm Hash digest
SHA256 26a7a413d6738ab9cb3a661ab8df3638227ce2c658113aa0e410b1c8e78608ba
MD5 a7760bad6eb6680483b906b3d4334554
BLAKE2b-256 4c601ab81c4430079a86560d8816b4e78d2e5ba9ac4ab8386817193b434bf415

See more details on using hashes here.

File details

Details for the file llama_index_tools_openai_image_generation-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_tools_openai_image_generation-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_openai_image_generation-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 727c8f72e20d534d10846d583a33002d72dfeca30c7f75e110ab49c749a83343
MD5 a182d1df02c52edf91dd448da03e69ae
BLAKE2b-256 c83c4bd2baad3c14396af31697602fba17bf8798f29e71770c0f87dcae4c52e7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page