Strands Nvidia NIM Provider
A minimal custom provider that fixes message formatting compatibility between Strands Agents SDK and Nvidia NIM API.
Problem Solved
The standard Strands LiteLLM integration fails with Nvidia NIM because:
- Strands formats messages as structured content:
[{"text": "content", "type": "text"}] - Nvidia NIM expects simple string content:
"content"
This provider bridges that gap by converting structured content to simple strings.
Installation
Option 1: Install from PyPI (Recommended)
pip install strands-nvidia-nim
Option 2: Install from GitHub
pip install git+https://github.com/yourusername/strands-nvidia-nim.git
Option 3: Local Development
git clone https://github.com/yourusername/strands-nvidia-nim.git
cd strands-nvidia-nim
pip install -e .
Quick Start
Option 1: Direct API Key
from strands import Agent
from strands_tools import calculator
from strands_nvidia_nim import NvidiaNIM
# Create the provider
model = NvidiaNIM(
api_key="your-nvidia-nim-api-key",
model_id="meta/llama-3.1-70b-instruct",
params={
"max_tokens": 1000,
"temperature": 0.7,
}
)
# Use with standard Strands Agent
agent = Agent(model=model, tools=[calculator])
agent("What is 123.456 * 789.012?")
Option 2: Environment Variables (Recommended)
# Set your API key as an environment variable
export NVIDIA_NIM_API_KEY=your-nvidia-nim-api-key
import os
from strands import Agent
from strands_tools import calculator
from strands_nvidia_nim import NvidiaNIM
model = NvidiaNIM(
api_key=os.getenv("NVIDIA_NIM_API_KEY"),
model_id="meta/llama-3.1-70b-instruct",
params={"max_tokens": 1000, "temperature": 0.7}
)
agent = Agent(model=model, tools=[calculator])
agent("What is 123.456 * 789.012?")
Available Models
Popular Nvidia NIM models:
meta/llama-3.1-70b-instruct- High quality, larger modelmeta/llama-3.1-8b-instruct- Faster, smaller modelmeta/llama-3.3-70b-instruct- Latest Llama modelmistralai/mistral-large- Mistral's flagship modelnvidia/llama-3.1-nemotron-70b-instruct- Nvidia-optimized
Configuration
model = NvidiaNIM(
api_key="your-api-key",
model_id="meta/llama-3.1-70b-instruct",
params={
"max_tokens": 1500,
"temperature": 0.7,
"top_p": 0.9,
"frequency_penalty": 0.0,
"presence_penalty": 0.0
}
)
Features
- ✅ Fixes BadRequestError - No more message formatting issues
- ✅ Minimal Code - Simple, focused solution
- ✅ Standard Strands Pattern - Uses
Agent(model=model, tools=[tools]) - ✅ Clean Output - Proper streaming without artifacts
- ✅ Error Handling - Context window overflow detection
Comparison
| Approach | Standard LiteLLM | This Provider |
|---|---|---|
| Message Format | ❌ Fails with structured content | ✅ Converts to string format |
| Setup Complexity | ⚠️ Requires workarounds | ✅ Simple, clean setup |
| Strands Integration | ⚠️ Compatibility issues | ✅ Native integration |
| Error Handling | ⚠️ Generic errors | ✅ Strands-specific errors |
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- 🐛 Bug Reports: GitHub Issues
- 💬 Discussions: GitHub Discussions
- 📖 Documentation: README
Metadata
Release files for strands-nvidia-nim 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| strands_nvidia_nim-1.0.0.tar.gz | 6.1 kB | Without provenance | Details for strands_nvidia_nim-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| strands_nvidia_nim-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for strands_nvidia_nim-1.0.0-py3-none-any.whl |
Total release size: 12.0 kB
Release files / strands_nvidia_nim-1.0.0.tar.gz
| Download URL | strands_nvidia_nim-1.0.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f3c65ebdfb257e17d0d276f4ceb5234034760b2b1753821db64beccc60c0bf3e
|
|
BLAKE2b-256 checksum How to use checksums |
3d0caa007154706c82e53b31ad8c91f1c386370a136449ce2dc1246ff952536e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Release files / strands_nvidia_nim-1.0.0-py3-none-any.whl
| Download URL | strands_nvidia_nim-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfce8324aec43704fae56d2deb03fa2e270cab9517dff0d50bd0b388f42c8c7e
|
|
BLAKE2b-256 checksum How to use checksums |
14481758236d28f70a9d8bd042ba83d1c4f2b0d63e1c62df19bd58ff28df5bfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Security for strands-nvidia-nim 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.