# ApiError AuthenticationException even correct API Key is provided

**URL:** <https://discuss.elastic.co/t/apierror-authenticationexception-even-correct-api-key-is-provided/353121>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [February 13, 2024, 5:30am UTC](https://discuss.elastic.co/t/apierror-authenticationexception-even-correct-api-key-is-provided/353121 "2024-02-13T05:30:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfulanchan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tfulanchan/32/131665_2.png) [@tfulanchan](https://discuss.elastic.co/u/tfulanchan)\
**Post date:** [February 13, 2024, 5:30am UTC](https://discuss.elastic.co/t/apierror-authenticationexception-even-correct-api-key-is-provided/353121/1 "2024-02-13T05:30:57Z")

</div>

Hello,

2nd day trial Elasticsearch Cloud. I have my Cloud API keys from "Organization \> API Keys \> Create API key". I am doing the [chatbot tutorial](https://www.elastic.co/search-labs/tutorials/chatbot-tutorial/chatbot-rag-app/backend).

This is my credentials and they will be removed once the problem is solved. I am pasting it here to identify what is going wrong. Please feel free to try my credentials on your own to solve this problem.

```auto
ELASTIC_CLOUD_ID="CLOUD_ID"

ELASTIC_API_KEY="API_KEY"

```

```auto
    raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
elasticsearch.AuthenticationException: AuthenticationException(401, 'security_exception', 'unable to authenticate with provided credentials and anonymous access is not allowed for this request')

```

The credentials should be correct. Can anyone tell why is there an authentication error?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 13, 2024, 6:44am UTC](https://discuss.elastic.co/t/apierror-authenticationexception-even-correct-api-key-is-provided/353121/2 "2024-02-13T06:44:20Z")

</div>

Hi @tfulanchan Welcome to the community.

Kinda a common mistake when getting started.

> [@tfulanchan](#):
>
> Organization \> API Keys \> Create API key".

That creates An API Key for using The ESS / Elastic Cloud API to create and modify whole clusters. Etc.

To work within an Elasticsearch cluster...I.e the REST API to load data and work inside an Elasticsearch cluster

Go to  
Kibana - Stack Management - API Keys

Make sure you get the correct format for the REST API

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [February 13, 2024, 11:35am UTC](https://discuss.elastic.co/t/apierror-authenticationexception-even-correct-api-key-is-provided/353121/3 "2024-02-13T11:35:45Z")

</div>

Hi @tfulanchan

I've removed your keys in your post and highly encourage you to delete the api key. Please dont post api-keys publicly so others are able to perform requests on your behalf.

See this page for creating an API key [Elastic Cloud — Elastic Search Labs](https://www.elastic.co/search-labs/tutorials/install-elasticsearch/elastic-cloud#creating-an-api-key)

---

<div class="post-metadata">

**Author:** ![tfulanchan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tfulanchan/32/131665_2.png) [@tfulanchan](https://discuss.elastic.co/u/tfulanchan)\
**Post date:** [February 14, 2024, 3:11pm UTC](https://discuss.elastic.co/t/apierror-authenticationexception-even-correct-api-key-is-provided/353121/4 "2024-02-14T15:11:04Z")

</div>

This is exactly where the confusion was and the answer I was looking for. Let's hope that these two will be named differently in the future to avoid confusion for Usability concerns.

Thank you Elastic!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 13, 2024, 3:12pm UTC](https://discuss.elastic.co/t/apierror-authenticationexception-even-correct-api-key-is-provided/353121/5 "2024-03-13T15:12:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
