Skip to main content

Python client for AWS Bedrock Gateway with IAM authentication

Project description

Bedrock Gateway Client

A Python client for AWS Bedrock Gateway with IAM authentication. Works with any private API Gateway setup for AWS Bedrock.

Features

  • Configurable - Works with any Bedrock Gateway deployment
  • No secrets required - Uses your AWS IAM credentials
  • Simple API - Just client.chat("message")
  • Multiple configuration methods - Constructor, environment variables, or config file
  • CLI included - Command-line interface for quick testing

Installation

pip install bedrock-gateway-client

Quick Start

from bedrock_gateway_client import BedrockClient

client = BedrockClient(
    gateway_url="https://your-api-gateway.execute-api.region.amazonaws.com/prod/invoke",
    region="us-east-1"
)

response = client.chat("Tell me about koalas")
print(response.text)
print(f"Tokens used: {response.tokens}")

Configuration Options

Direct Configuration

from bedrock_gateway_client import BedrockClient

client = BedrockClient(
    gateway_url="https://your-gateway.execute-api.region.amazonaws.com/prod/invoke",
    region="us-east-1"
)

Environment Variables

export BEDROCK_GATEWAY_URL="https://your-gateway.execute-api.region.amazonaws.com/prod/invoke"
export BEDROCK_GATEWAY_REGION="us-east-1"
from bedrock_gateway_client import BedrockClient

client = BedrockClient()  # Uses environment variables

Global Configuration

from bedrock_gateway_client import configure, chat

configure(
    gateway_url="https://your-gateway.execute-api.region.amazonaws.com/prod/invoke",
    region="us-east-1",
    save=True
)

# Now use simple chat function
response = chat("Tell me about koalas")
print(response)

Usage Examples

Basic Chat

response = client.chat(
    "What is AWS Bedrock?",
    model="sonnet-4.5",
    max_tokens=500
)

print(response.text)
print(f"Tokens: {response.tokens}")
print(f"Latency: {response.latency_ms}ms")

With System Prompt

response = client.chat(
    "What is 2+2?",
    system="You are a helpful math tutor.",
    model="sonnet-4.5"
)

Multi-turn Conversation

# First turn
response1 = client.chat("My name is Alice")

# Build history
history = [
    {"role": "user", "content": [{"text": "My name is Alice"}]},
    {"role": "assistant", "content": [{"text": response1.text}]}
]

# Second turn with context
response2 = client.chat(
    "What's my name?",
    conversation_history=history
)

Command-Line Interface

# Configure
bedrock-gateway configure --gateway-url "https://..." --region us-east-1

# Chat
bedrock-gateway chat "Tell me about AWS Bedrock" --model sonnet-4.5

# Check identity
bedrock-gateway whoami

Response Object

response.text           # The generated text
response.tokens         # Total tokens used
response.input_tokens   # Input tokens
response.output_tokens  # Output tokens
response.latency_ms     # Response time in milliseconds
response.request_id     # Unique request ID
response.model          # Model used
response.stop_reason    # Why generation stopped
response.raw_response   # Full raw response

Authentication

Uses your AWS credentials automatically:

  • Default AWS credentials (~/.aws/credentials)
  • AWS profile: BedrockClient(profile="my-profile")
  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  • IAM role (when running on EC2/Lambda/ECS)

Roy Morgan Setup

If you're at Roy Morgan, configure once:

from bedrock_gateway_client import configure

configure(
    gateway_url="https://vpce-03162ee3093fbd956-w5fiddec.execute-api.ap-southeast-2.vpce.amazonaws.com/prod/invoke",
    region="ap-southeast-2",
    model_map={
        'sonnet-4.5': 'au.anthropic.claude-sonnet-4-5-20250929-v1:0',
        'haiku-4.5': 'au.anthropic.claude-haiku-4-5-20251001-v1:0',
    },
    save=True
)

Then use:

from bedrock_gateway_client import chat
print(chat("Tell me about koalas"))

License

MIT License - see LICENSE file for details

Support

For issues, open a GitHub issue at: https://github.com/parveshh/bedrock-gateway-client/issues

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

bedrock_gateway_client-1.0.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

bedrock_gateway_client-1.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bedrock_gateway_client-1.0.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for bedrock_gateway_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e1be1621e16ddf9c0f02ba8cc5a930542edba236c38ff353dbcb065afc54bce3
MD5 39ed9ba9068abf3d4cf7e8dbfd025fd2
BLAKE2b-256 24e940d1fbad9c081c773809c5850ce65575f67470b0bd6c0c555089408daa85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bedrock_gateway_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb6722c9f5e4c05303881ad507ef800353dace378711be08b5ec87ff846114c2
MD5 fb54e13f687bc1a8ce551761346d9e61
BLAKE2b-256 e13f32e7d3bc8959e43c761931bebca00592cdd9d9258e519cbdde861ee1ea40

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