Skip to main content

Octo AI Python Library

fern shield

The Octo AI Python Library provides convenient access to the Octo AI API from applications written in Python.

Documentation

API reference documentation is available here.

Whisper is not currently available. If you're interested in using speech-to-text models, please contact us at customer-success@octo.ai

Installation

Add this dependency to your project's build file:

pip install octoai
# or
poetry add octoai

Usage

Simply import OctoAI and start making calls to our API.

from octoai.client import OctoAI
from octoai.text_gen import ChatMessage

client = OctoAI(
    api_key="YOUR_API_KEY"  # Defaults to your OCTOAI_TOKEN environment variable
)
client.text_gen.create_chat_completion(
    messages=[
        ChatMessage(
            role="role",
        )
    ],
    model="model",
)

Async Client

The SDK also exports an async client so that you can make non-blocking calls to our API.

from octoai.client import AsyncOctoAI
from octoai.text_gen import ChatMessage

client = AsyncOctoAI(
  api_key="YOUR_API_KEY" # Defaults to your OCTOAI_TOKEN environment variable
)

async def main() -> None:
    await client.text_gen.create_chat_completion(
        messages=[
            ChatMessage(
                role="role",
            )
        ],
        model="model",
    )

asyncio.run(main())

OctoAI Services

The client nests key services within the provisioned client:

from octoai.client import OctoAI

client = OctoAI(...)

# The image generation service
client.image_gen.generate_sd(...)

# The text generation service
client.text_gen.create_chat_completion(...)

# The asset library service
client.asset_library.create(...)

# The fine-tuning service
client.fine_tuning.create(...)

Exception Handling

All errors thrown by the SDK will be subclasses of ApiError.

import octoai

try:
  client.text_gen.create_chat_completion(...)
except octoai.core.ApiError as e: # Handle all errors
  print(e.status_code)
  print(e.body)

Advanced

Retries

The OctoAI SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit.

A request is deemed retriable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 409 (Conflict)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries request option to configure this behavior.

from octoai.client import OctoAI

client = OctoAI(...)

# Override retries for a specific method
client.text_gen.create_chat_completion(..., {
    max_retries=5
})

Timeouts

By default, requests time out after 60 seconds. You can configure this with a timeout option at the client or request level.

from octoai.client import OctoAI

client = OctoAI(
    # All timeouts are 20 seconds
    timeout=20.0,
)

# Override timeout for a specific method
client.text_gen.create_chat_completion(..., {
    timeout_in_seconds=20.0
})

Custom HTTP client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

import httpx

from octoai.client import OctoAI

client = OctoAI(
    http_client=httpx.Client(
        proxies="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

Beta Status

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version. This way, you can install the same version each time without breaking changes.

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Metadata

Release files for octoai 1.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for octoai 1.11.0
File Size Uploaded Provenance Actions
octoai-1.11.0.tar.gz 51.9 kB Without provenance Details for octoai-1.11.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for octoai 1.11.0
File Interpreter ABI Platform Actions
octoai-1.11.0-py3-none-any.whl Python 3 none any Details for octoai-1.11.0-py3-none-any.whl

Total release size: 165.6 kB

Release files / octoai-1.11.0.tar.gz

Download URL octoai-1.11.0.tar.gz
Size 51.9 kB
Tags Source
SHA-256 checksum
How to use checksums
aaea3b6a1d88dde526018560557aa2bcf183ccbd5563bcdf7e65a54efd58151e
BLAKE2b-256 checksum
How to use checksums
03e392824a85c61ccd0ad62703cb1d3805335525cafdcc24e060b58540f55193
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1071-azure

Release files / octoai-1.11.0-py3-none-any.whl

Download URL octoai-1.11.0-py3-none-any.whl
Size 113.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c6ef50dffe3beac20f16e8b949069ba9ea970fccbe2476ea7ea15302e670a15
BLAKE2b-256 checksum
How to use checksums
c02851a9eec201e1ab45ca80845ef1dcc0efd56a1237f2d18344a55c7be36c49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1071-azure

Security for octoai 1.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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