# Get an API Key

{% hint style="info" %}
In order to receive an API Key, you must have a Mobile Text Alerts account. [Click here](https://mobile-text-alerts.com/signup-smsapi) to sign up for one!
{% endhint %}

### Generate an API Key

API Keys can be generated in the Mobile Text Alerts platform dashboard.

1. Visit [Settings](https://platform.mobile-text-alerts.com/settings) for your account. This is under the three-dot menu in the top right of the platform dashboard.
2. Select the [Developer](https://platform.mobile-text-alerts.com/#settings_developer) tab or scroll down to **Developer Resources**.
3. Click the <mark style="color:green;background-color:green;">GENERATE A NEW KEY</mark> button. Enter a name for the new **API Key**.

{% hint style="warning" %}
Once generated, store this key in a safe place. The key will no longer be available to view after clicking **“Accept”**.
{% endhint %}

This **API Key** is used to make authenticated calls to the Mobile Text Alerts API.

### Bearer Token Authentication

This **API Key** is used as a bearer token when making requests to the API. A bearer token is included in the request header to grant a user or application access to a protected endpoint.

**Header structure:** `"Authorization: Bearer {myAPIKey}"`

#### Example request to verify the API Key

The examples below send a request with a bearer token to the [<mark style="color:blue;">`/verify-api-key`</mark>](#get-auth-verify-api-key) endpoint. This verifies the **API Key** is valid:

{% tabs %}
{% tab title="cURL" %}

```bash
curl -L \
  -H 'Authorization: Bearer <APIKey>' \
  'https://api.mobile-text-alerts.com/v3/auth/verify-api-key'
```

{% endtab %}

{% tab title="Node.js" %}

```js
// Run with: node --env-file=.env verify.js
async function main() {
  const apiKey = process.env.MTA_API_KEY;

  const response = await fetch(
    "https://api.mobile-text-alerts.com/v3/auth/verify-api-key",
    {
      method: "GET",
      headers: {
        "Authorization": `Bearer ${apiKey}`,
        "Accept": "*/*",
      },
    }
  );

  console.log("STATUS:", response.status);
  console.log("CONTENT-TYPE:", response.headers.get("Content-Type"));

  const contentType = response.headers.get("Content-Type");
  if (contentType && contentType.includes("application/json")) {
    const data = await response.json();
    console.log(data);
  } else {
    const text = await response.text();
    console.log(text);
  }
}

main().catch((err) => {
  console.error("Request failed:", err);
  process.exitCode = 1;
});
```

{% endtab %}

{% tab title="Python" %}
Example `verify.py` file (requires `pip install requests python-dotenv`):

<pre class="language-python"><code class="lang-python"><strong>import os
</strong>import requests
from dotenv import load_dotenv

load_dotenv()

api_key = os.getenv("MTA_API_KEY")

response = requests.get(
   "https://api.mobile-text-alerts.com/v3/auth/verify-api-key",
   headers={
       "Authorization": f"Bearer {api_key}",
       "Accept": "*/*",
   },
)

print("STATUS:", response.status_code)
print("CONTENT-TYPE:", response.headers.get("Content-Type"))

if response.headers.get("Content-Type", "").startswith("application/json"):
   print(response.json())
else:
   print(response.text)

</code></pre>

{% endtab %}
{% endtabs %}

If the key is valid, the API returns the message: `"API Key verified"`

```json
//Example successful response
{"message":"API Key verified",
"data":{"name":"Account111111111","email":"example@mobile-text-alerts.com"}}          
```

A <mark style="color:$success;">`200`</mark> indicates success. See [error-response-codes](https://developers.mobile-text-alerts.com/api-basics/error-response-codes "mention") for possible error codes.

## GET /auth/verify-api-key

> Verify API Key

```json
{"openapi":"3.0.0","info":{"title":"Mobile Text Alerts API","version":"8.0.0"},"servers":[{"url":"https://api.mobile-text-alerts.com/v3"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"apiKey"}},"schemas":{"VerifyApiKey.Response":{"allOf":[{"$ref":"#/components/schemas/IApiResponse"},{"type":"object","properties":{"data":{"type":"object","properties":{"name":{"type":"string"},"email":{"type":"string"}},"required":["name","email"]}},"required":["data"]}]},"IApiResponse":{"type":"object","properties":{"success":{"type":"boolean"},"error":{"type":"string"},"message":{"type":"string"},"data":{}},"required":[]}},"responses":{"BadRequestError":{"description":"BadRequestError","content":{"application/json":{"schema":{"type":"object","properties":{"httpCode":{"type":"number","enum":[400]},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"},"type":{"type":"string","enum":["bad_request_error"]},"name":{"type":"string","enum":["MTABadRequestError"]},"requestId":{"type":"string","format":"uuid"}}}}}},"UnauthorizedError":{"description":"UnauthorizedError","content":{"application/json":{"schema":{"type":"object","properties":{"httpCode":{"type":"number","enum":[401]},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"},"type":{"type":"string","enum":["unauthorized_error"]},"name":{"type":"string","enum":["MTAUnauthorizedError"]},"requestId":{"type":"string","format":"uuid"}}}}}},"ForbiddenError":{"description":"ForbiddenError","content":{"application/json":{"schema":{"type":"object","properties":{"httpCode":{"type":"number","enum":[403]},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"},"type":{"type":"string","enum":["forbidden_error"]},"name":{"type":"string","enum":["MTAForbiddenError"]},"requestId":{"type":"string","format":"uuid"},"reason":{}}}}}},"InternalServerError":{"description":"InternalServerError","content":{"application/json":{"schema":{"type":"object","properties":{"httpCode":{"type":"number","enum":[500]},"message":{"type":"string"},"timestamp":{"type":"string","format":"date-time"},"type":{"type":"string","enum":["internal_server_error"]},"name":{"type":"string","enum":["MTAInternalServerError"]},"requestId":{"type":"string","format":"uuid"}}}}}}}},"paths":{"/auth/verify-api-key":{"get":{"tags":["Auth"],"summary":"Verify API Key","operationId":"auth_verify_api_key","responses":{"200":{"description":"Success","headers":{"RateLimit-Limit":{"description":"The maximum number of requests that the consumer is permitted to make per window","schema":{"type":"integer"}},"RateLimit-Remaining":{"description":"The number of requests remaining in the current rate limit window","schema":{"type":"integer"}},"RateLimit-Reset":{"description":"The remaining window before the rate limit resets in milliseconds","schema":{"type":"integer"}},"Retry-After":{"description":"The number of seconds to wait before retrying the request","schema":{"type":"integer"}},"X-RateLimit-Limit":{"description":"The maximum number of requests that the consumer is permitted to make per window","schema":{"type":"integer"}},"X-RateLimit-Remaining":{"description":"The number of requests remaining in the current rate limit window","schema":{"type":"integer"}},"X-RateLimit-Reset":{"description":"The remaining window before the rate limit resets in milliseconds","schema":{"type":"integer"}},"X-Request-ID":{"description":"A unique identifier for the request","schema":{"type":"string","format":"uuid"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/VerifyApiKey.Response"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"500":{"$ref":"#/components/responses/InternalServerError"}}}}}}
```

With a verified API key, you’re ready to send real messages. See [send-a-message](https://developers.mobile-text-alerts.com/getting-started/send-a-message "mention") to learn more.


---

# 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://developers.mobile-text-alerts.com/getting-started/get-an-api-key.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.
