Skip to main content

Quick Start

Get started with Modal in under 2 minutes:
from portkey_ai import Portkey

# 1. Install: pip install portkey-ai
# 2. Add @modal provider in model catalog
# 3. Use it:

portkey = Portkey(api_key="PORTKEY_API_KEY")

response = portkey.chat.completions.create(
    model="@modal/your-model-name",
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)
Tip: You can also set provider="@modal" in Portkey() and use just model="your-model-name" in the request.

Add Provider in Model Catalog

Before making requests, add Modal to your Model Catalog:
  1. Go to Model Catalog → Add Provider
  2. Select Modal
  3. Enter your Modal API credentials
    • Modal supports API Key (Bearer token) or Custom Headers (modal-key and modal-secret)
  4. Custom Host: Enter your Modal deployment endpoint (e.g., https://your-modal-deployment.modal.run)
  5. Name your provider (e.g., modal)
Note: Custom host configuration is set once in Model Catalog and applies to all requests using this provider.

Complete Setup Guide

See all setup options and detailed configuration instructions

Modal Documentation

Explore the official Modal documentation

Streaming

Stream responses for real-time output:
from portkey_ai import Portkey

portkey = Portkey(api_key="PORTKEY_API_KEY")

stream = portkey.chat.completions.create(
    model="@modal/your-model",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

Supported Endpoints and Parameters

EndpointSupported Parameters
/chat/completionsmessages, max_tokens, temperature, top_p, stream, presence_penalty, frequency_penalty

Next Steps

For complete SDK documentation:

SDK Reference

Complete Portkey SDK documentation