Skip to content

feat: Adding portkey.ai gateway as a custom model #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

fede-dash
Copy link
Contributor

@fede-dash fede-dash commented Jun 10, 2025

🚀 Portkey Integration for Strands SDK

This PR adds first-class support for Portkey — a gateway platform for LLM providers — into the Strands SDK. It introduces a unified, configurable, and extensible way to interact with multiple AI models (OpenAI, Anthropic via Bedrock, Gemini, and more) through a single abstraction.

The integration emphasizes tool use and streaming completions, and lays the foundation for upcoming features like multi-modal interactions (images, audio — coming in a future PR).


🔌 What is Portkey?

Portkey is a powerful LLM gateway that offers:

  • 🔄 Unified API access to multiple model providers
  • 🚦 Smart routing based on performance, reliability, or cost
  • 📊 Built-in observability and analytics (latency, usage)
  • ♻️ Retry, fallback, and caching strategies
  • 🔑 Key and model management for dynamic overrides

Portkey is trusted by industry leaders like Notion, Descript, and Ramp as the go-to abstraction for managing complex LLM infrastructure at scale.


✅ Supported Providers

This integration supports — and has been tested with — the following:

  • OpenAI (GPT-4, GPT-3.5)
  • Anthropic via Amazon Bedrock
  • Amazon Bedrock-native models
  • Google Gemini
  • Other Portkey-supported providers

🛠️ Tool Use Support

  • 🧠 OpenAI (native function-calling)
  • 🧠 Anthropic (via Bedrock, partial support)

🌟 Benefits of Portkey Integration

Benefit Description
Model Agility Swap providers without changing SDK logic
Unified Tooling Consistent handling of tool_calls across providers
Resilience Add retries, rate limits, and observability
Flexibility Customize temperature, tokens, and streaming behavior
Cost Optimization Route to cheaper or fallback models

🌍 Real-World Usage

Without Portkey support, many real-world systems cannot adopt the SDK due to centralized governance and observability requirements.

Organizations already standardizing on Portkey include:

  • 🧾 Notion – AI copilots with dynamic routing
  • 💳 Ramp – cost-based fallback and observability
  • 🎞️ Descript – creative workflows across models
  • 🧩 Puzzle, DeepOpinion, and other AI-first startups

📎 Reference: Portkey Customers


🧱 Technical Implementation

This PR extends the Model interface within the Strands SDK, Amazon’s agent platform for intelligent task automation.

Features implemented:

  • ✅ Streaming responses
  • ✅ Tool calling (tool_calls / tool_use)
  • ✅ System prompt injection
  • ✅ Token and parameter configuration per model
  • ✅ Model-agnostic formatting of inputs/outputs

🧠 Coming Soon: A follow-up PR will enable multi-modal inputs (images and audio) to support rich sensory data for agents.


🆕 New Class: PortkeyModel

Key responsibilities:

  • Implements the Model interface
  • Handles provider-specific tool behaviors (OpenAI vs Bedrock)
  • Formats and streams messages with structured deltas
  • Manages tool call lifecycle (initiation, input, response)
  • Applies defensive guards (e.g., malformed payloads, token limits)
  • Supports ToolSpec mapping and schema encoding

🧪 Validation

Tested and validated for:

  • ✔️ Chat completions
  • ✔️ Streaming responses
  • ✔️ Tool calling with parameters
  • ✔️ Tool result integration
  • ✔️ Multi-provider backends:
    • GPT-4 (OpenAI)
    • Claude (Bedrock)
    • Gemini
    • Jurassic/Titan (Bedrock-native)

📋 Next Steps

  • Add multi-modal support (images, audio)
  • Integrate Portkey metrics into internal observability
  • Add routing and fallback config support
  • Enable runtime A/B testing between providers

🔗 References


📝 PR Metadata

Description

This PR adds comprehensive documentation for the new Portkey integration in the Strands SDK. It includes installation instructions, usage examples, configuration options, and troubleshooting guidance tailored to help developers quickly adopt and understand Portkey as a provider interface for language models like OpenAI, Anthropic (via Bedrock), and others.

Related Issues

Documentation PR


🔀 Type of Change

  • New content addition
  • Content update/revision
  • Structure/organization improvement
  • Typo/formatting fix
  • Bug fix
  • Documentation update
  • Breaking change
  • Other (please describe):

🧪 Testing

  • hatch fmt --linter
  • hatch fmt --formatter
  • hatch test --all
  • Verified no regressions across dependent repos:
    • agent-docs
    • agent-tools
    • agent-cli

✅ Checklist

  • I have read the CONTRIBUTING document
  • My changes follow the project's documentation style
  • I have tested the documentation locally using mkdocs serve
  • Links in the documentation are valid and working
  • Images/diagrams are properly sized and formatted
  • All new and existing tests pass

Motivation and Context

Portkey support was recently added to the Strands SDK to provide a unified gateway for multiple LLM providers. This documentation update ensures users can:

  • Understand what Portkey is and how it fits into the Strands ecosystem
  • Install the optional dependency correctly
  • Configure models, providers, and parameters appropriately
  • Resolve common installation errors
  • Reference reliable external docs for further configuration

It also serves as the foundational guide for future features such as multi-modal support and advanced routing.


Areas Affected

  • docs/portkey.md — New section added for Portkey integration:
    • Overview of Portkey’s purpose
    • Installation steps
    • Usage example with code
    • Full configuration table (model_id, params, provider, etc.)
    • Troubleshooting module import error
    • References to Portkey and OpenAI documentation

Screenshots

📸 Not applicable — text-only documentation change. Code block samples included in file.


Additional Notes

This documentation aligns with the broader goals of making the SDK pluggable and provider-agnostic, catering to real-world enterprise environments that already leverage Portkey for observability, routing, and API abstraction.

For broader context and the technical motivations behind this integration, please refer to the parent PR in the SDK:

🔗 Portkey Integration for Strands SDK


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@fede-dash fede-dash marked this pull request as ready for review June 10, 2025 05:17
@fede-dash
Copy link
Contributor Author

fede-dash commented Jun 10, 2025

Using Portkey with openai 3.5 turbo

Screen.Recording.2025-06-10.at.2.12.32.AM.mov

@fede-dash
Copy link
Contributor Author

image

@fede-dash
Copy link
Contributor Author

Docs : strands-agents/docs#87

@fede-dash fede-dash force-pushed the portkey-ai branch 7 times, most recently from 9e10570 to c790516 Compare June 10, 2025 07:21
feat: Adding portkey.ai gateway as a custom model

feat: Adding portkey.ai gateway as a custom model
@fede-dash
Copy link
Contributor Author

cc: @awsarron - Would appreciate your review as many companies use this technique to connect to GenAI models.

@fede-dash
Copy link
Contributor Author

@awsarron
Copy link
Member

Hi @fede-dash, thank you for your contribution!

We're working through Strands' built-in model provider strategy at the moment. To help us with this discussion, could you please share details about what builders get with Portkey over LiteLLM, which already supports hundreds of model providers and has a built-in model provider in Strands.

@fede-dash
Copy link
Contributor Author

fede-dash commented Jun 16, 2025 via email

@fede-dash fede-dash force-pushed the portkey-ai branch 2 times, most recently from 7b0b1ee to f815280 Compare June 17, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants