Installing Claude for Sheets

Easily enable Claude for Sheets using the following steps:

  1. Get your Claude API key: You will not be able to use Claude for Sheets without a developer API key. For more information on how to acquire an API key, see getting access to Claude.
  2. Install the Claude for Sheets extension
    1. Click here to access the Claude for Sheets extension or search Claude for Sheets in the add-on marketplace.
    2. Click the blue Install button and accept the permissions.
  3. Connect your API key: Enter your API key at Extensions > Claude for Sheets™ > Enter your Anthropic API Key. You may need to wait or refresh for “Enter your Anthropic API key” to appear as an option.

After you see the green ‘verified’ checkmark ✅ appear, Claude will be activated and ready within your Google Sheet.

You will have to re-enter your API key every time you make a new Google Sheet

Permissions

During installation, the Claude for Sheets extension will ask for a variety of permissions needed to function properly. Although the permissions requested to run Claude in Sheets are broad, please be assured that we only process the specific pieces of data that users ask Claude to run on. This data is never used to train our generative models.

Extension permissions include:

  • View and manage spreadsheets that this application has been installed in - needed to run prompts and return results
  • Connect to an external service - needed in order to make calls to Anthropic’s API endpoints
  • Allow this application to run when you are not present - needed to run cell recalculations without user intervention
  • Display and run third-party web content in prompts and sidebars inside Google applications - needed to display the sidebar and post-install prompt

Cell Recalculation

You can manually recalculate #ERROR!, ⚠ DEFERRED ⚠ or ⚠ THROTTLED ⚠cells by selecting from the recalculate options within the Claude for Sheets extension menu.


How to use Claude for Sheets

Claude functions

There are two main functions you can use to call Claude using Claude for Sheets:

1. CLAUDE()

=CLAUDE(prompt, model, params...)

CLAUDE() is the simplest way to call Claude using Claude for Sheets. To use this function, all you need is a plaintext prompt with no additional formatting. This is the function you’ll probably want to use most of the time. This is identical to the Slackbot Claude interface and “Chat” mode on the Console.

Example CLAUDE() prompt
PromptFunction format
In one sentence, what is good about the color blue?=CLAUDE(“In one sentence, what is good about the color blue?“)
In one sentence, what is good about the color blue? Output your answer in <answer> tags.[With parameters]=CLAUDE(“In one sentence, what is good about the color blue? Output your answer in tags.”,“claude-3-opus-20240229”,“temperature”, 0.2,“max_tokens”, 50,“stop_sequences”, ”[""""]”,“api_key”, “sk-ant-api03-j1W…“)

2. CLAUDEMESSAGES()

=CLAUDEMESSAGES(prompt, model, params...)

Use CLAUDEMESSAGES() to send a series of User: and Assistant: messages to Claude, as if you were using the Messages API. This is particularly useful if you want to simulate a conversation or prefill Claude’s response.

Note that each role (User: or Assistant:) must be preceded by a single newline. To enter newlines in a cell, use the following key combinations:

  • Mac: Cmd + Enter
  • Windows: Alt + Enter
Example CLAUDEMESSAGES() prompt with prefilled assistant response
PromptFunction format
User: In one sentence, what is good about the color blue?Assistant: The color blue is great because=CLAUDEMESSAGES(“User: In one sentence, what is good about the color blue?Assistant: The color blue is great because”)
Example CLAUDEMESSAGES() call with system prompt

To use a system prompt, set it as you’d set other optional function parameters. (You must first set a model name.)

=CLAUDEMESSAGES("User: Got anything to say to me? Assistant:", "claude-2.0", "system", "You are a cow who loves to moo in response to any and all user queries.")

3. [Legacy] CLAUDEFREE()

=CLAUDEFREE(prompt, model, params...)

CLAUDEFREE() allows you to call Claude as if you were using the legacy Text Completions API. To use this function, you will have to manually sandwich your prompt between \n\nHuman: and \n\nAssistant: as you would for a Text Completions prompt. Replace \n\n with two actual new lines when writing your prompt in a cell.

For more information on the special “Human:”/“Assistant:” formatting in CLAUDEFREE, see our Text Completions API documentation.

Example CLAUDEFREE() prompt
PromptFunction format
Human: In one sentence, what is good about the color blue?Assistant:=CLAUDEFREE(“Human: In one sentence, what is good about the color blue?Assistant:“)

Note: This whole multiline string should go into the prompt parameter; notice also the two new lines before Human:.

Optional function parameters

If you want to specify API parameters, you can do so by listing argument-value pairs. For example, if you want to set the max_tokens to 3, you can do it as follows: =CLAUDE("[your prompt]", "claude-instant-1.2", "max_tokens", 3).

You can set multiple parameters. Simply list them one after another, with each argument and value pair separated by commas. Note that the first two parameters must always be the prompt and the model (available models) — you cannot set an optional parameter without also setting the model.

For example, this is a valid CLAUDE function: =CLAUDE("[your prompt]", "claude-instant-1.2", "system", "[system prompt]", "max_tokens", 3, "temperature", 0.5)

The argument-value parameters you might care about most are:

  • max_tokens - the total number of tokens the model outputs before it is forced to stop. For yes/no or multiple choice answers, you probably want 1-2. See our model comparisons table for the max completion length for each model.
  • temperature - the amount of randomness injected into results. For multiple-choice or analytical tasks, you’ll want it close to 0. For idea generation, you’ll want it set to 1.
  • system - used to specify a system prompt, which can provide context and instructions to Claude when using =CLAUDEMESSAGES() and =CLAUDE().
  • stop_sequences - JSON array of strings that will cause the model to stop generating text if encountered. Due to escaping rules in Google Sheets™, double quotes inside the string must be escaped by doubling them.
  • api_key - used to specify a particular API key with which to call Claude

Claude for Sheets guides & examples

Prompt engineering interactive tutorial

API version note

All Claude for Sheets spreadsheets linked within this section, such as the prompt engineering interactive tutorial and the prompting examples workbench, currently use the legacy CLAUDEFREE() function which calls the Text Completions API. These will be updated soon to utilize CLAUDEMESSAGES() and the Messages API.

Visit our in-depth prompt engineering interactive tutorial utilizing the Claude for Sheets add-on to learn or brush up on beginner to advanced prompt engineering techniques.

Note that just as with the rest of Claude for Sheets, you will need an API key to interact with the tutorial.

Claude for Sheets prompting examples

For example prompts, prompting structures, and Claude-powered spreadsheets, visit our Claude for Sheets prompting examples workbench. There, you can find examples for tasks such as the following:

  • Longform document Q&A
  • Information extraction
  • Removing PII
  • Customer support chatbot using FAQ
  • Academic tutor
  • Prompt chaining
  • Function calling
  • And much more!

Claude for Sheets workbook template

Make a copy of our Claude for Sheets workbook template to get started with your own Claude for Sheets work!


Troubleshooting

NAME? Error: Unknown function: ‘claude’.

  1. Ensure that you have enabled the extension for use in the current sheet
    1. Go to Extensions > Add-ons > Manage add-ons
    2. Click on the triple dot menu at the top right corner of the Claude for Sheets extension and make sure “Use in this document” is checked
  2. Refresh the page

Can’t enter API key

  1. Wait 20 seconds, then check again
  2. Refresh the page and wait 20 seconds again
  3. Uninstall and reinstall the extension

Further information

For more information regarding this extension, see the Claude for Sheets Google Workspace Marketplace overview page.