paws icon indicating copy to clipboard operation
paws copied to clipboard

Support for AWS API key for use with PAWS

Open benhmin opened this issue 3 months ago • 4 comments

I am looking for a potential way to use API keys with ellmer and the AWS bedrock implementation. I have been able to connect up and use the chat object with AWS via the PAWS integration and SSO, but have been unable to find documentation on how one might use this package with API keys instead of SSO authentication.

The AWS bedrock documentation does provide a way to use API keys using their boto3 package: https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys-use.html

`import os import boto3

If you already set the API key as an environment variable, you can comment this line out

os.environ['AWS_BEARER_TOKEN_BEDROCK'] = "${api-key}"

Create an Amazon Bedrock client

client = boto3.client( service_name="bedrock-runtime", region_name="us-east-1" # If you've configured a default region, you can omit this line )

Define the model and message

model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0" messages = [{"role": "user", "content": [{"text": "Hello"}]}]

response = client.converse( modelId=model_id, messages=messages, )`

They also have some documentation about using an API key in the header request of an HTTP API request.

I have been unable to find documentation on how to make this happen in PAWS despite trying to set the environmental variable. Is there a way? Please help if able. Thank you!

benhmin avatar Oct 09 '25 18:10 benhmin

Related to this issue I filed with ellmer but it seems like maybe more of a PAWS question.

benhmin avatar Oct 09 '25 18:10 benhmin

Hi sorry about the delay in my reply. Currently this isn't supported however I will start working on it shortly. In the meantime feel free to raise and PR regarding this.

DyfanJones avatar Oct 22 '25 15:10 DyfanJones

Apologies in the delay, I have had some dental work and it has really slowed me down in fixing these issues. After the latest cran release i will address this :)

DyfanJones avatar Nov 17 '25 18:11 DyfanJones

Actually I believe I can get this in with the latest paws.common release. Here is a sneak preview:

options(paws.log_level = 4)
library(paws)

cfg <- config(credentials(profile = "paws"), region = "us-east-1")
client <- bedrockruntime(cfg)

content <- client$converse(
  modelId = "us.anthropic.claude-haiku-4-5-20251001-v1:0",
  messages = list(list(
    role = "user",
    content = list(list(text = "1+1?"))
  ))
)$output$message$content
#> DEBUG [2025-11-18 15:42:27.576]: -> POST /model/us.anthropic.claude-haiku-4-5-20251001-v1%3A0/converse HTTP/2
#> -> Host: bedrock-runtime.us-east-1.amazonaws.com
#> -> Accept: */*
#> -> Accept-Encoding: deflate, gzip
#> -> User-Agent: paws/0.8.6 (R4.5.1; darwin20; aarch64)
#> -> Content-Length: 58
#> -> X-Amz-Date: 20251118T154227Z
#> -> Authorization: AWS4-HMAC-SHA256 Credential=1234/20251118/us-east-1/bedrock/aws4_request, SignedHeaders=content-length;host;x-amz-date, Signature=1234
#> -> 
#> DEBUG [2025-11-18 15:42:28.374]: <- HTTP/2 200 
#> DEBUG [2025-11-18 15:42:28.374]: <- date: Tue, 18 Nov 2025 15:42:28 GMT
#> DEBUG [2025-11-18 15:42:28.374]: <- content-type: application/json
#> DEBUG [2025-11-18 15:42:28.374]: <- content-length: 321
#> DEBUG [2025-11-18 15:42:28.374]: <- x-amzn-requestid: 0c60e0d5-2af3-4da4-8f33-c0d03e3b9386
#> DEBUG [2025-11-18 15:42:28.374]: <-

sapply(content, \(cont) cont$text)
#> [1] "1 + 1 = 2"

Sys.setenv("AWS_BEARER_TOKEN_BEDROCK" = 'MY_TOKEN')
content <- client$converse(
  modelId = "us.anthropic.claude-haiku-4-5-20251001-v1:0",
  messages = list(list(
    role = "user",
    content = list(list(text = "1+1?"))
  ))
)$output$message$content
#> DEBUG [2025-11-18 15:42:28.392]: -> POST /model/us.anthropic.claude-haiku-4-5-20251001-v1%3A0/converse HTTP/2
#> -> Host: bedrock-runtime.us-east-1.amazonaws.com
#> -> Accept: */*
#> -> Accept-Encoding: deflate, gzip
#> -> User-Agent: paws/0.8.6 (R4.5.1; darwin20; aarch64)
#> -> Content-Length: 58
#> -> Authorization: Bearer MY_TOKEN
#> -> 
#> DEBUG [2025-11-18 15:42:29.291]: <- HTTP/2 200 
#> DEBUG [2025-11-18 15:42:29.291]: <- date: Tue, 18 Nov 2025 15:42:29 GMT
#> DEBUG [2025-11-18 15:42:29.291]: <- content-type: application/json
#> DEBUG [2025-11-18 15:42:29.291]: <- content-length: 321
#> DEBUG [2025-11-18 15:42:29.291]: <- x-amzn-requestid: 3c79044f-e052-46fc-be0c-0e50592fbbea
#> DEBUG [2025-11-18 15:42:29.292]: <-

sapply(content, \(cont) cont$text)
#> [1] "1 + 1 = 2"

Created on 2025-11-18 with reprex v2.1.1

DyfanJones avatar Nov 18 '25 15:11 DyfanJones