Using API Keys

Using Blockspring API keys ensures you 100k requests per month. It also lets us provide you with meaningful stats and security. Let's walk through the basics of Blockspring API keys.

First, you'll want to to get your API key.


Two types of keys

There are two types of Blockspring API keys: function keys and an account key.

Function keys are only allowed to run the specific function they're associated with. The next section shows how to find a function's key. Here are typical use-cases for using function keys:

  • You want to run a Blockspring function using Javascript directly from a website. Your function key is exposed in the client, but it only lets someone run that specific function. No other functions on your account are compromised.
  • You are sharing a script or analysis publicly. Again, your function key can be shared, and users will only be able to run that specific function.

Your account key has permissions to create new functions with your account, and to see and run all public or private functions on your account. Here are typical use-cases for using your account key:

  • You are calling Blockspring functions from a secure server or device. Typically, you'll want to set your account key to the BLOCKSPRING_API_KEY environment variable. That way, you do not have to hardcode the key into your application, and you can run all Blockspring functions without actually inputting the key as a parameter.
  • Some 3rd party integrations may ask for your API key. That way, you can run Blockspring functions directly from those applications. Only provide this key if it's with an application you trust


How to include an API key in your function

Let's say you found a Blockspring function you want to include in your project, how do you do so with an API key? Let's walk through an example:

  • Step 0: You found a function and arrived at its homepage.
  • Step 1: Click "Integrations" to pull up the sample code snippets for calling your function. You should see something like this: Use in code
  • Step 2: Choose your preferred language and copy/paste that code snippet into your application or program. You are now using your function level API key.


When you don't need an API key

Do not include your API key when running a Blockspring function from within another Blockspring function. That way, you can publish open-source functions that call other Blockspring functions, and your key is not exposed.

The reason this technique works is because we automatically set the BLOCKSPRING_API_KEY environment variable on Blockspring machines.

See this function for an example of a function calling another function without including the API key.

If you have any questions let us know (in the chat below)!