Skip to main content

Amazon Nova API model provider for Strands Agents SDK

Project description

Strands Nova

Amazon Nova API model provider for Strands Agents SDK.

This package provides integration between Amazon's Nova API (an OpenAI-compatible API for Amazon's Nova family of models) and the Strands Agents SDK, enabling access to Nova Pro, Nova Premier, reasoning models, and other capabilities.

Installation

pip install strands-amazon-nova

Or with development dependencies:

pip install strands-amazon-nova[dev]

Quick Start

import asyncio
import os
from amazon_nova import NovaAPIModel

async def main():
    # Initialize the Nova model
    model = NovaAPIModel(
        api_key=os.getenv("NOVA_API_KEY"),
        model_id="nova-lite-v2",  # Required parameter
        params={
            "max_tokens": 1000,
            "temperature": 0.7,
        }
    )
    
    # Simple conversation
    messages = [
        {
            "role": "user",
            "content": [{"text": "Hello! How are you?"}]
        }
    ]
    
    # Stream the response
    async for chunk in model.stream(messages=messages):
        if "contentBlockDelta" in chunk:
            delta = chunk["contentBlockDelta"]["delta"]
            if "text" in delta:
                print(delta["text"], end="", flush=True)

asyncio.run(main())

Features

  • Direct Nova API Integration: Uses httpx for direct API calls (no OpenAI SDK dependency)
  • Streaming Support: Full support for streaming responses with Server-Sent Events (SSE)
  • Tool Calling: Complete support for function/tool calling
  • System Tools: Support for Nova system tools (grounding, code interpreter)
  • Structured Output: Type-safe structured output using Pydantic models
  • Multi-modal Inputs: Support for text, images, documents, and audio
  • Error Handling: Proper handling of Nova API errors including throttling and context overflow
  • Reasoning Content: Support for models with reasoning capabilities
  • Strands Compatible: Fully compatible with the Strands Agents SDK

Supported Models

To see all available models for your account:

curl -L 'https://api.nova.amazon.com/v1/models' \
  -H 'Authorization: Bearer YOUR_API_KEY'

Configuration

Basic Configuration

from amazon_nova import NovaAPIModel

model = NovaAPIModel(
    api_key=os.getenv("NOVA_API_KEY"),   # Required: Nova API key
    model_id="nova-pro-v1",              # Required: Model ID
    base_url="https://api.nova.amazon.com/v1",  # Optional, default shown
    timeout=300.0,                       # Optional, request timeout in seconds
    params={                             # Optional: Model parameters
        "max_tokens": 4096,              # Maximum tokens to generate
        "max_completion_tokens": 4096,   # Alternative to max_tokens
        "temperature": 0.7,              # Sampling temperature (0.0-1.0)
        "top_p": 0.9,                    # Nucleus sampling (0.0-1.0)
        "reasoning_effort": "medium",    # For reasoning models: "low", "medium", "high"
        "system_tools": ["nova_grounding", "nova_code_interpreter"] # Available system tools from Nova API
        "metadata": {},                  # Additional metadata
    }
)

Supported Parameters in params:

  • max_tokens (int): Maximum tokens to generate (deprecated, use max_completion_tokens)
  • max_completion_tokens (int): Maximum tokens to generate
  • temperature (float): Controls randomness (0.0 = deterministic, 1.0 = maximum randomness)
  • top_p (float): Nucleus sampling threshold
  • reasoning_effort (str): For reasoning models - "low", "medium", or "high"
  • system_tools (list): Available system tools from the Nova API - currently nova_grounding and nova_code_interpreter
  • metadata (dict): Additional request metadata
  • Any additional parameters will be passed through to the API for future extensibility

Using with Strands Agents

from strands import Agent
from amazon_nova import NovaAPIModel

model = NovaAPIModel(
    api_key=os.getenv("NOVA_API_KEY"),   # Required: Nova API key
,
    model_id="nova-pro-v1",  # Required
    params={
        "temperature": 0.7,
        "max_tokens": 2048
    }
)

agent = Agent(
    model=model,
    system_prompt="You are a helpful assistant."
)

# Use the agent
response = await agent.run("Tell me about quantum computing")

Error Handling

The package provides custom exceptions for Nova-specific errors, along with support for Strands SDK exceptions:

from strands.types.exceptions import (
    ContextWindowOverflowException,
    ModelThrottledException
)
from amazon_nova import (
    NovaAPIException,           # Base exception for all Nova API errors
    NovaValidationException,    # HTTP 400 validation errors
    NovaModelNotFoundException, # HTTP 404 model not found
    NovaModelException          # HTTP 500 internal model errors
)

try:
    async for chunk in model.stream(messages=messages):
        # Process chunks
        pass
except ContextWindowOverflowException as e:
    print(f"Context window exceeded: {e}")
    # Reduce message history or content size
except ModelThrottledException as e:
    print(f"Rate limited: {e}")
    # Implement retry with backoff
except NovaValidationException as e:
    print(f"Validation error: {e}")
    # Check request parameters
except NovaModelNotFoundException as e:
    print(f"Model not found: {e}")
    # Verify model_id is correct
except NovaModelException as e:
    print(f"Model error: {e}")
    # Nova API internal error
except NovaAPIException as e:
    print(f"Nova API error: {e}")
    # Catch-all for other Nova errors
except Exception as e:
    print(f"Unexpected error: {e}")

Custom Nova Exceptions:

  • NovaAPIException: Base exception for all Nova API errors
  • NovaValidationException: Raised for HTTP 400 validation errors (malformed requests, invalid parameters)
  • NovaModelNotFoundException: Raised for HTTP 404 errors (model not found or inaccessible)
  • NovaModelException: Raised for HTTP 500 errors (internal model service errors)

Strands SDK Exceptions:

  • ContextWindowOverflowException: Raised when input exceeds the model's context window
  • ModelThrottledException: Raised when requests are rate-limited (HTTP 429)

Getting Your API Key

  1. Visit https://nova.amazon.com/dev-apis
  2. Sign in with your Amazon account
  3. Generate your API key
  4. Set it as an environment variable: export NOVA_API_KEY=your-key-here

Configuration Types

NovaAPIModelParams

The NovaAPIModelParams TypedDict provides type hints for all supported parameters:

class NovaAPIModelParams(TypedDict, total=False):
    max_tokens: int                          # Deprecated, use max_completion_tokens
    max_completion_tokens: int               # Maximum tokens to generate
    temperature: float                       # Sampling temperature (0.0-1.0)
    top_p: float                            # Nucleus sampling (0.0-1.0)
    reasoning_effort: str                   # "low", "medium", or "high"
    metadata: dict[str, Any]                # Additional metadata
    system_tools: list[Union[NovaSystemTool, str]]  # Built-in system tools

Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check .

# Type checking
mypy src/amazon_nova

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues with the Nova API itself, contact: For issues with this package, please open a GitHub issue.

Acknowledgments

This package is built for Strands Agents SDK.

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_amazon_nova-1.0.1.tar.gz (278.5 kB view details)

Uploaded Source

Built Distribution

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

strands_amazon_nova-1.0.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file strands_amazon_nova-1.0.1.tar.gz.

File metadata

  • Download URL: strands_amazon_nova-1.0.1.tar.gz
  • Upload date:
  • Size: 278.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for strands_amazon_nova-1.0.1.tar.gz
Algorithm Hash digest
SHA256 75ba3c982e9b89f3b3804c14d4f08669a0f8016b02ece222fd0c4959aa9a6ed9
MD5 fa8ff2bf926834ec79b47607c787fff9
BLAKE2b-256 3eae8ae81f0f9313da3f3a538e774edcd9d45fd6b54688eff4131734d2b6ca58

See more details on using hashes here.

Provenance

The following attestation bundles were made for strands_amazon_nova-1.0.1.tar.gz:

Publisher: publish.yml on amazon-nova-api/strands-nova

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file strands_amazon_nova-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for strands_amazon_nova-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 753530ece1338dc825063a784dea3cdf0fe3c7f9eb8f7b97280a5c0db8557a61
MD5 fb7912c1ca79ab6700632b213829fb19
BLAKE2b-256 f48f08eebf7974abe5a7510893d62d39ee90bb239b1c8e839eb71817b2d57142

See more details on using hashes here.

Provenance

The following attestation bundles were made for strands_amazon_nova-1.0.1-py3-none-any.whl:

Publisher: publish.yml on amazon-nova-api/strands-nova

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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