Skip to main content

Heroku Managed Inference

The llama-index-llms-heroku package contains LlamaIndex integrations for building applications with models on Heroku's Managed Inference platform. This integration allows you to easily connect to and use AI models deployed on Heroku's infrastructure.

Installation

pip install llama-index-llms-heroku

Setup

1. Create a Heroku App

First, create an app in Heroku:

heroku create $APP_NAME

2. Create and Attach AI Models

Create and attach a chat model to your app:

heroku ai:models:create -a $APP_NAME claude-3-5-haiku

3. Export Configuration Variables

Export the required configuration variables:

export INFERENCE_KEY=$(heroku config:get INFERENCE_KEY -a $APP_NAME)
export INFERENCE_MODEL_ID=$(heroku config:get INFERENCE_MODEL_ID -a $APP_NAME)
export INFERENCE_URL=$(heroku config:get INFERENCE_URL -a $APP_NAME)

Usage

Basic Usage

from llama_index.llms.heroku import Heroku
from llama_index.core.llms import ChatMessage, MessageRole

# Initialize the Heroku LLM
llm = Heroku()

# Create chat messages
messages = [
    ChatMessage(
        role=MessageRole.SYSTEM, content="You are a helpful assistant."
    ),
    ChatMessage(
        role=MessageRole.USER,
        content="What are the most popular house pets in North America?",
    ),
]

# Get response
response = llm.chat(messages)
print(response)

Using Environment Variables

The integration automatically reads from environment variables:

import os

# Set environment variables
os.environ["INFERENCE_KEY"] = "your-inference-key"
os.environ["INFERENCE_URL"] = "https://us.inference.heroku.com"
os.environ["INFERENCE_MODEL_ID"] = "claude-3-5-haiku"

# Initialize without parameters
llm = Heroku()

Using Parameters

You can also pass parameters directly:

import os

llm = Heroku(
    model=os.getenv("INFERENCE_MODEL_ID", "claude-3-5-haiku"),
    api_key=os.getenv("INFERENCE_KEY", "your-inference-key"),
    inference_url=os.getenv(
        "INFERENCE_URL", "https://us.inference.heroku.com"
    ),
    max_tokens=1024,
)

Text Completion

# Simple text completion
response = llm.complete("Explain the importance of open source LLMs")
print(response.text)

Available Models

For a complete list of available models, see the Heroku Managed Inference documentation.

Error Handling

The integration includes proper error handling for common issues:

  • Missing API key
  • Invalid inference URL
  • Missing model configuration

Additional Information

For more information about Heroku Managed Inference, visit the official documentation.

Download files

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

Source Distribution

llama_index_llms_heroku-0.3.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

llama_index_llms_heroku-0.3.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_heroku-0.3.0.tar.gz.

File metadata

  • Download URL: llama_index_llms_heroku-0.3.0.tar.gz
  • Upload date:
  • Size: 5.0 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_llms_heroku-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6178fd4b8e413b4b1f6d9370e5eebb8a16c4b59c94f2d7fb6196317d8fa946fc
MD5 b7da78816e07c2a39332537b2d118594
BLAKE2b-256 e6ae7686fe652e1769df13a9c8fb34e6a9997fca83f24c9d7d96f45614f468e5

See more details on using hashes here.

File details

Details for the file llama_index_llms_heroku-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_llms_heroku-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 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_llms_heroku-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd6aae37c8d767ee1feb9109bc71d538c5fe65d2fa9f46ce1718a03f0661ccbc
MD5 67ccfe79c7b417c2d6eb40881f429304
BLAKE2b-256 f4aab0ecc73d59785f55db8ebe044150bdf06c8fe8285949b8e7717711947371

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.1

2 files

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

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