Commit ee006bf
Fede Kamelhar
feat: Adding portkey.ai gateway as a custom model
This PR adds first-class support for **Portkey**, a gateway platform for LLM providers, into the Strands SDK. It enables 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 foundational support for future capabilities like **multi-modal interactions** (images, audio — coming in a future PR).
---
[Portkey](https://portkey.ai) is a powerful LLM gateway that provides:
- **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 becoming the go-to model abstraction layer for companies scaling LLM usage — including Notion, Descript, Ramp, and others — because it makes managing model complexity simple, modular, and scalable.
---
This integration supports and has been tested with:
- **OpenAI** (GPT-4, GPT-3.5)
- **Anthropic**, via **Amazon Bedrock**
- **Amazon Bedrock-native models**
- **Google Gemini**
- **Other providers** supported by Portkey configuration
- **Tool Use capabilities** for:
- OpenAI (native function-calling support)
- Anthropic (via Bedrock with partial support)
---
Adding Portkey unlocks significant benefits:
| Benefit | Description |
|--------|-------------|
| **Model Agility** | Swap providers without changing SDK logic |
| **Unified Tooling** | Consistent handling of `tool_calls` across models |
| **Resilience** | Add retries, rate limits, and observability |
| **Flexibility** | Customize parameters like temperature, tokens, and stream |
| **Cost Optimization** | Route to cheaper models or fallback options |
---
Portkey is not just a convenience — it is a **requirement** for SDK adoption in many real-world AI systems.
Leading companies already standardize on Portkey. Without first-class support, **these companies cannot use the SDK**, as their LLM access, observability, and governance are fully routed through Portkey.
- **Notion** – internal AI copilots with dynamic routing
- **Ramp** – cost-based model fallback and observability
- **Descript** – creative workflows across providers
- **Puzzle**, **DeepOpinion**, and other AI-first orgs
📎 **Reference**: [Portkey Customers](https://www.portkey.ai/customers)
Supporting Portkey makes the Strands SDK **immediately compatible** with the infrastructure already powering major AI systems — greatly reducing integration effort.
---
This implementation extends the `Model` interface within the **Strands SDK**, Amazon’s agent platform for intelligent task automation.
- ✅ Streaming responses
- ✅ Tool calling (`tool_calls` / `tool_use`)
- ✅ System prompt injection
- ✅ Token configuration per model
- ✅ Model-agnostic formatting of inputs/outputs
> 🧠 **Coming Soon**: In a follow-up PR, we will add **multi-modal capabilities** (images and audio input), further expanding the power of Strands agents to handle rich sensory data.
---
This PR introduces a new model provider class:
- `PortkeyModel`, implementing the full `Model` interface
- Handles provider-specific tool use behavior (OpenAI vs Bedrock)
- Formats and streams messages with structured deltas
- Manages tool call life cycle: initiation, input, completion
- Defensive checks for context window and malformed payloads
- Full support for `ToolSpec` mapping and schema encoding
All logic is structured to allow future expansion to other Portkey-supported capabilities (e.g., caching, retry policies, routing rules).
---
This feature was validated across the following dimensions:
- ✔️ Basic chat completions
- ✔️ Streaming token responses
- ✔️ Tool calling with input parameters
- ✔️ Tool result handoff
- ✔️ Multiple model backends:
- OpenAI GPT-4 (tools)
- Anthropic Claude (via Bedrock)
- Gemini (streaming + simple use)
- Bedrock-native (Jurassic, Titan)
---
- [ ] Add multi-modal support (images, audio)
- [ ] Integrate Portkey usage metrics into internal observability stack
- [ ] Add routing and fallback policies via Portkey configuration
- [ ] Enable A/B experimentation between providers at runtime
---
- [Portkey.ai Documentation](https://docs.portkey.ai/)
- [Portkey Customer Base](https://www.portkey.ai/customers)
- [Amazon Bedrock Overview](https://docs.aws.amazon.com/bedrock/)
- [OpenAI Function Calling](https://platform.openai.com/docs/guides/function-calling)
- [Strands SDK](https://github.com/aws/strands-sdk)
---
feat: Adding portkey.ai gateway as a custom model
feat: Adding portkey.ai gateway as a custom model
feat: Adding portkey.ai gateway as a custom model
feat: Adding portkey.ai gateway as a custom model1 parent aff928c commit ee006bf
5 files changed
Lines changed: 630 additions & 1 deletion
File tree
- src
- strands/models
- tests/strands/models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
145 | 157 | | |
146 | 158 | | |
147 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| |||
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
110 | | - | |
| 115 | + | |
111 | 116 | | |
112 | 117 | | |
113 | 118 | | |
| |||
Whitespace-only changes.
0 commit comments