Open watany-dev opened 6 months ago
Howdy @watany-dev, the example you provided here has quite a bit more than the example in our docs (combining some of the Workers AI stuff, which is great overall but makes it harder to eval what exactly is wrong).
If you just run the example present in our docs, does that one work? Or does it also error out on you?
This issue was closed automatically because there has been no response from the original author. As it stands currently, we don't have enough information to take action. If you believe this issue was closed in error, a) apologies and b) open a new issue and reference this one in the body.
Hello!
I can confirm that the sample in your docs also does not work. This is the code that I am using:
import { AwsClient } from 'aws4fetch'
export default {
async fetch(request, env, ctx) {
const requestData = {
inputText: "What does ethereal mean?"
};
const headers = {
'Content-Type': 'application/json'
};
// sign the original request
const stockUrl = new URL("https://bedrock-runtime.us-east-1.amazonaws.com/model/amazon.titan-embed-text-v1/invoke")
const awsClient = new AwsClient({
accessKeyId: accessKey,
secretAccessKey: secretKey,
region: region,
service: "bedrock"
});
const presignedRequest = await awsClient.sign(stockUrl.toString(), {
method: "POST",
headers: headers
});
console.log(presignedRequest);
// change the signed request's host to AI Gateway
const stockUrlSigned = new URL(presignedRequest.url);
stockUrlSigned.host = "gateway.ai.cloudflare.com"
stockUrlSigned.pathname = `/v1/${cfAccountId}/${gatewayName}/aws-bedrock/bedrock-runtime/${region}/model/amazon.titan-embed-text-v1/invoke`
// make request
const response = await fetch(stockUrlSigned, {
method: 'POST',
headers: presignedRequest.headers,
body: JSON.stringify(requestData)
})
if (response.ok && response.headers.get('content-type')?.includes('application/json')) {
const data = await response.json();
return new Response(JSON.stringify(response));
} else {
// Display the data in the console
const data = await response.text();
console.log(data);
return new Response("Invalid response", { status: 500 });
}
},
};
The data
response I get is always:
{"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."}
I can also confirm that it is not a problem with my credentials, and I can see the request reaching Cloudflare's AI Gateway in my dashboard. It dies on hitting the amazon endpoint. I think it has something to do with the presignedRequest
but I have no idea what. I've tried a few different models for which I have access and the results have been the same.
Thanks for re-flagging @kittykatattack, re-opening and raising for our ENG team.
Is there a solution?
Existing documentation URL(s)
Probably a problem with the signing process, this sample doesn't work(gateway/bedrock), IAM hardcoded something strong so it's not an AWS IAM issue and I can confirm that I have sufficient permissions on the AI Gateway (/app).
https://developers.cloudflare.com/ai-gateway/providers/bedrock/
What changes are you suggesting?
I would like a sample code that works well enough
Additional information
No response