Skip to main content

Heroku MIA SDK for Python

A Python SDK for Heroku's Managed Inference API (MIA), providing easy access to AI models through a LangChain-compatible interface.

🚀 Quick Start

Installation

pip install heroku-langchain-aisdk

Basic Usage

import os
from heroku_mia_sdk import HerokuMia

# Set your environment variables
os.environ["HEROKU_API_KEY"] = "your-api-key"
os.environ["INFERENCE_MODEL_ID"] = "claude-3-7-sonnet"
os.environ["INFERENCE_URL"] = "https://us.inference.heroku.com"

# Create client and send message
client = HerokuMia()
response = client.invoke("What is the capital of France?")
print(response.content)

📋 Features

  • LangChain Compatible: Works seamlessly with LangChain ecosystem
  • Streaming Support: Real-time response streaming
  • Tool Calling: Function calling capabilities
  • Async Support: Full async/await support
  • Type Safe: Built with Pydantic for type safety

🔧 Configuration

Environment Variables

Variable Description Required
HEROKU_API_KEY Your Heroku API key Yes
INFERENCE_MODEL_ID Model to use (e.g., claude-3-7-sonnet) Yes
INFERENCE_URL Inference endpoint URL Yes

Getting Your API Key

  1. Log in to your Heroku account
  2. Navigate to Account Settings
  3. Generate an API key
  4. Use the format: inf-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

📖 Examples

Basic Chat

from heroku_mia_sdk import HerokuMia

client = HerokuMia()
response = client.invoke("Hello, how are you?")
print(response.content)

Streaming Chat

from heroku_mia_sdk import HerokuMia

client = HerokuMia()
for chunk in client.stream("Tell me a story"):
    print(chunk.content, end="", flush=True)

Chat with Tools

from heroku_mia_sdk import HerokuMia
from langchain_core.tools import tool

@tool
def get_weather(city: str) -> str:
    """Get weather for a city."""
    return f"The weather in {city} is sunny and 25°C"

client = HerokuMia()
client = client.bind_tools([get_weather])
response = client.invoke("What's the weather in Paris?")

Multiple Messages

from heroku_mia_sdk import HerokuMia
from langchain_core.messages import HumanMessage, SystemMessage

client = HerokuMia()
messages = [
    SystemMessage(content="You are a helpful assistant."),
    HumanMessage(content="What is Python?")
]
response = client.invoke(messages)
print(response.content)

🛠️ Development

Local Installation

git clone https://github.com/heroku/heroku-langchain-aisdk
cd heroku-langchain-aisdk/python
pip install -e .

Running Examples

# Set environment variables
export HEROKU_API_KEY="your-api-key"
export INFERENCE_MODEL_ID="claude-3-7-sonnet"
export INFERENCE_URL="https://us.inference.heroku.com"

# Run examples
python examples/example_chat_basic.py
python examples/example_chat_streaming.py
python examples/example_chat_tools.py

Development Dependencies

pip install -e ".[dev]"

📚 API Reference

HerokuMia Class

The main client class for interacting with Heroku's Managed Inference API.

Methods

  • invoke(input) - Send a message and get response
  • stream(input) - Stream response chunks
  • bind_tools(tools) - Bind tools for function calling
  • with_config(config) - Configure client settings

Parameters

  • model_id (str): Model identifier
  • api_key (str): Heroku API key
  • base_url (str): API base URL
  • temperature (float): Response randomness (0.0-1.0)
  • max_tokens (int): Maximum response tokens

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details.

🆘 Support

🔗 Related

Metadata

Release files for heroku-langchain-aisdk 0.2.1

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

Source distribution (sdist)

Source distribution for heroku-langchain-aisdk 0.2.1
File Size Uploaded
heroku_langchain_aisdk-0.2.1.tar.gz 25.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for heroku-langchain-aisdk 0.2.1
File Interpreter ABI Platform
heroku_langchain_aisdk-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.4 kB

Release files / heroku_langchain_aisdk-0.2.1.tar.gz

Download URL heroku_langchain_aisdk-0.2.1.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
43aa15a06ece6c56896420ab354aa99d314b67b803b16a45d7c75be8175b421a
BLAKE2b-256 checksum
How to use checksums
038eddb4ff492a37fb1841a39ee01e689c5e22a9bafa0f1ea4350c92643282a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release files / heroku_langchain_aisdk-0.2.1-py3-none-any.whl

Download URL heroku_langchain_aisdk-0.2.1-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24a91d62c2d7b9014599c8aa93cf10941ed2598900c386fd56ab7bfe92c6b368
BLAKE2b-256 checksum
How to use checksums
462b1592ea9e37dcf24872b3804f2395d04d0800aa47d9955e316ec0779ea8e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.1.0

2 release 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