Skip to content

Instantly share code, notes, and snippets.

Created June 2, 2023 07:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save deepakness/d8ae6ba14b751f61a96f02c04b452758 to your computer and use it in GitHub Desktop.
Connect Anthropic Claude API to Google Sheets
function callClaude(promptText) {
// Your API key should be specified here.
const apiKey = 'your_api_key';
// Set necessary parameters for your request.
const requestBody = {
prompt: "\n\nHuman: " + promptText + "\n\nAssistant: ",
model: "claude-v1",
max_tokens_to_sample: 100,
stop_sequences: ["\n\nHuman:"]
// Configure the options for your request.
const requestOptions = {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(requestBody),
headers: {
'x-api-key': apiKey,
// Make the request and parse the response.
const apiResponse = UrlFetchApp.fetch('', requestOptions);
const responseText = JSON.parse(apiResponse.getContentText());
// Extract the Assistant's response and return it.
const assistantResponse = responseText.completion.trim();
return assistantResponse;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment