Skip to main content

Nvidia NIM provider for Strands Agents SDK

Project description

Strands Nvidia NIM Provider

A minimal custom provider that fixes message formatting compatibility between Strands Agents SDK and Nvidia NIM API.

PyPI version Python 3.8+ License: MIT

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 model
  • meta/llama-3.1-8b-instruct - Faster, smaller model
  • meta/llama-3.3-70b-instruct - Latest Llama model
  • mistralai/mistral-large - Mistral's flagship model
  • nvidia/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

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

strands_nvidia_nim-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

strands_nvidia_nim-1.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file strands_nvidia_nim-1.0.0.tar.gz.

File metadata

  • Download URL: strands_nvidia_nim-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for strands_nvidia_nim-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f3c65ebdfb257e17d0d276f4ceb5234034760b2b1753821db64beccc60c0bf3e
MD5 af9abfb6ba0713f31e84eac00c87a563
BLAKE2b-256 3d0caa007154706c82e53b31ad8c91f1c386370a136449ce2dc1246ff952536e

See more details on using hashes here.

File details

Details for the file strands_nvidia_nim-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for strands_nvidia_nim-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfce8324aec43704fae56d2deb03fa2e270cab9517dff0d50bd0b388f42c8c7e
MD5 af67de38c43f6b3e1f7d61f027be915c
BLAKE2b-256 14481758236d28f70a9d8bd042ba83d1c4f2b0d63e1c62df19bd58ff28df5bfc

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