Skip to main content

Heroku MIA SDK for Python - AI inference client for Heroku's managed inference API

Project description

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-mia-sdk

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-mia-sdk-python
cd heroku-mia-sdk-python/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

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

heroku_langchain_aisdk-0.1.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

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

heroku_langchain_aisdk-0.1.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file heroku_langchain_aisdk-0.1.0.tar.gz.

File metadata

  • Download URL: heroku_langchain_aisdk-0.1.0.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for heroku_langchain_aisdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7bf4b69fb627440e6933f1c532ca90a25ce6b1cf6bd9f4be3be8cc4dabc459bb
MD5 7bbc53adae9769802a756ca70a497788
BLAKE2b-256 f17f92b7bf9270cc961633dc4c92ec1db66b0bddb1ac5dc169babc87d2b2ca3b

See more details on using hashes here.

File details

Details for the file heroku_langchain_aisdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for heroku_langchain_aisdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05a5ddc11ad13ddd18006edd5e67397b8792f51ddb2e95b541533e7d5bbbbd89
MD5 e8be5588d33e6e00357b37040bbb6cab
BLAKE2b-256 ba77e8a2b288ba5853ecde3ca0673f2efb6e51afddbd9e343fa0e496c87c0588

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