# How to use SECRETS in Functions?

Our main aim with Functions is to allow users to chain API calls and connect their other services to Gooey.AI's workflows. Several services like Supabase, Firebase and more require their own API keys. Now you can store them in your [API Keys tab](https://gooey.ai/account/api-keys/) in the Accounts Page.&#x20;

### Step 1

Head over to [Gooey.AI Functions](https://gooey.ai/functions)

### **Step 2**

Set up your API call. In this example, we'll create an API call to Open Weather Map, so that it can share real-time weather stats with the user.&#x20;

```javascript
async ({ city_name }) => {
  const API_KEY = process.env.YOUR_API_KEY;
  if (!API_KEY) throw new Error("API key not found in environment variables.");
  const encodedCityName = encodeURIComponent(city_name);
  const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${encodedCityName}&appid=${API_KEY}&units=metric`);
  if (!response.ok) throw new Error(`Error ${response.status}: ${response.statusText}`);
  return { weather_data: await response.json() };
};
```

Here `process.env.YOUR_API_KEY` calls the secret key from your "Secrets".&#x20;

### Step 3

Scroll down to the "Secrets" section in the Functions Workflow. Select the API you need for this function to work successfully. &#x20;

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FE5VvNhNCpoAarUYCh5cH%2FScreen%20Recording%202025-01-06%20at%203.00.32%E2%80%AFPM%20processed.gif?alt=media&#x26;token=ca1982e8-8b6c-4eac-9aa0-3f243cdcfb98" alt=""><figcaption></figcaption></figure>

### Step 4

Hit "Run" and Save the function.&#x20;

{% hint style="info" %}
NOTE:  Before saving the workflow check if your response output is correct.
{% endhint %}

### Step 5

Add the saved Functions workflow in AI Copilot or other Gooey.AI Workflows.&#x20;

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FnegDH6nanltlZSjh9XyV%2FScreen%20Recording%202025-01-06%20at%203.15.23%E2%80%AFPM%20processed.gif?alt=media&#x26;token=b7e17dd5-f9ae-47cf-9567-b87c510a34ee" alt=""><figcaption></figcaption></figure>

***

Learn more about adding SECRETS to your Workspaces here:

{% embed url="<https://docs.gooey.ai/guides/how-to-use-workspaces/how-to-add-secrets-in-your-workspace>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gooey.ai/tools/how-to-use-gooey-functions/how-to-use-secrets-in-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
