# Recommended methods for handling API keys with CloudQuery

**URL:** <https://community.cloudquery.io/t/recommended-methods-for-handling-api-keys-with-cloudquery/413>\
**Category:** CloudQuery Plugins\
**Created:** [February 2, 2024, 1:41pm UTC](https://community.cloudquery.io/t/recommended-methods-for-handling-api-keys-with-cloudquery/413 "2024-02-02T13:41:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![creative-iguana](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@creative-iguana](https://community.cloudquery.io/u/creative-iguana)\
**Post date:** [February 2, 2024, 1:41pm UTC](https://community.cloudquery.io/t/recommended-methods-for-handling-api-keys-with-cloudquery/413/1 "2024-02-02T13:41:58Z")

</div>

What is the recommended way to handle API keys? Should they be set as environment variables, and then inserted into the config file’s spec for source and destination? If so, how do I insert them?

---

<div class="post-metadata">

**Author:** ![herman](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/herman/32/27_2.png) [@herman](https://community.cloudquery.io/u/herman)\
**Post date:** [February 2, 2024, 1:49pm UTC](https://community.cloudquery.io/t/recommended-methods-for-handling-api-keys-with-cloudquery/413/2 "2024-02-02T13:49:50Z")

</div>

Hi @creative-iguana 👋

Do you mean CloudQuery API keys? Or API keys for the underlying plugins?

If you mean the CloudQuery API key, you can follow the instructions [here](https://docs.cloudquery.io/docs/deployment/generate-api-key) to generate one and then do:

```auto
export CLOUDQUERY_API_KEY=<your-api-key>

```

before running:

```auto
cloudquery sync

```

This should be all you need.

If you mean for the underlying plugins, then yes, you should export them and then you can use environment variable expansion in the config to insert them: [Environment Variable Substitution](https://docs.cloudquery.io/docs/advanced-topics/environment-variable-substitution).

---

<div class="post-metadata">

**Author:** ![creative-iguana](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@creative-iguana](https://community.cloudquery.io/u/creative-iguana)\
**Post date:** [February 2, 2024, 1:50pm UTC](https://community.cloudquery.io/t/recommended-methods-for-handling-api-keys-with-cloudquery/413/3 "2024-02-02T13:50:44Z")

</div>

Thanks, that’s what I was looking for—how to expand environment variables in config, necessary for accessing source APIs.

Hm, I am trying to use this method, but it keeps telling me it can’t find the file, and I have tried many different variations. Where should the relative path to the file start from? The location of the plugin directory, or the CloudQuery binary, or?

---

<div class="post-metadata">

**Author:** ![herman](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/herman/32/27_2.png) [@herman](https://community.cloudquery.io/u/herman)\
**Post date:** [February 2, 2024, 2:04pm UTC](https://community.cloudquery.io/t/recommended-methods-for-handling-api-keys-with-cloudquery/413/4 "2024-02-02T14:04:46Z")

</div>

I think the issue might be related to the working directory from which the CloudQuery binary is executed. Could you try using an absolute path and see if that resolves the problem?

---

<div class="post-metadata">

**Author:** ![creative-iguana](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@creative-iguana](https://community.cloudquery.io/u/creative-iguana)\
**Post date:** [February 2, 2024, 2:07pm UTC](https://community.cloudquery.io/t/recommended-methods-for-handling-api-keys-with-cloudquery/413/5 "2024-02-02T14:07:35Z")

</div>

That is correct, thanks. It’s working now.
