Skip to content

Commit eb2971f

Browse files
committed
gptel-bedrock: add bearer-token argument to backend
1 parent 364030b commit eb2971f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

README.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ Register a backend with
11161116
#+end_src
11171117

11181118
AWS has numerous credential provisions; we follow this order precedence,
1119+
- (argument) ~:aws-bearer-token~
11191120
- (env. variable) ~AWS_BEARER_TOKEN_BEDROCK~
11201121
- (argument) ~:aws-profile~
11211122
If this option is specified, the Bedrock-backend uses the shared AWS config and credentials files to obtain credentials based on the AWS Profile selected. If ~:aws-profile~ is set to the keyword ~:static~, the IAM credentials are imported without a profile argument.

gptel-bedrock.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,11 @@ REGION is one of apac, eu or us."
595595
(or (alist-get model gptel-bedrock--model-ids nil nil #'eq)
596596
(error "Unknown Bedrock model: %s" model))))
597597

598-
(defun gptel-bedrock--curl-args (region profile)
598+
(defun gptel-bedrock--curl-args (region profile bearer-token)
599599
"Generate the curl arguments to get a bedrock request signed for use in REGION.
600600
601601
PROFILE specifies the aws profile to use for aws configure export-credentials."
602-
(let ((bearer-token (getenv "AWS_BEARER_TOKEN_BEDROCK"))
602+
(let ((bearer-token (or bearer-token (getenv "AWS_BEARER_TOKEN_BEDROCK")))
603603
(output-args (unless (memq system-type '(windows-nt ms-dos))
604604
'("--output" "/dev/stdout"))))
605605
(if bearer-token
@@ -628,7 +628,7 @@ PROFILE specifies the aws profile to use for aws configure export-credentials."
628628
(models gptel--bedrock-models)
629629
(model-region nil)
630630
stream curl-args request-params
631-
(aws-profile nil)
631+
aws-profile aws-bearer-token
632632
(protocol "https"))
633633
"Register an AWS Bedrock backend for gptel with NAME.
634634
@@ -638,12 +638,13 @@ REGION - AWS region name (e.g. \"us-east-1\")
638638
MODELS - The list of models supported by this backend
639639
MODEL-REGION - one of apac, eu, us or nil
640640
AWS-PROFILE - the aws profile to use for aws configure export-credentials
641+
AWS-BEARER-TOKEN - the aws bearer-token for authenticating with AWS
641642
CURL-ARGS - additional curl args
642643
STREAM - Whether to use streaming responses or not.
643644
REQUEST-PARAMS - a plist of additional HTTP request
644645
parameters (as plist keys) and values supported by the API."
645646
(declare (indent 1))
646-
(unless (getenv "AWS_BEARER_TOKEN_BEDROCK")
647+
(unless (or aws-bearer-token (getenv "AWS_BEARER_TOKEN_BEDROCK"))
647648
(unless (and gptel-use-curl (version<= "8.9" (gptel-bedrock--curl-version)))
648649
(error "Bedrock-backend requires curl >= 8.9, but gptel-use-curl := %s, curl-version := %s"
649650
gptel-use-curl (gptel-bedrock--curl-version))))
@@ -659,7 +660,7 @@ parameters (as plist keys) and values supported by the API."
659660
:endpoint "" ; Url is dynamically constructed based on other args
660661
:stream stream
661662
:coding-system (and stream 'binary)
662-
:curl-args (lambda () (append curl-args (gptel-bedrock--curl-args region aws-profile)))
663+
:curl-args (lambda () (append curl-args (gptel-bedrock--curl-args region aws-profile aws-bearer-token)))
663664
:request-params request-params
664665
:url
665666
(lambda ()

0 commit comments

Comments
 (0)