# Call an API over HTTP

Every API on the hub is called through the same gateway, with the same key and the same response headers.

> This page is for developers calling APIs from their own code. Using an AI agent? You don't need any of this: see [Connect AI agents (MCP)](https://zylalabs.com/docs/mcp).

## Before your first call

1. Get your [API key](https://zylalabs.com/docs/api-keys).
2. Open the API in the [catalog](https://zylalabs.com/api-marketplace) and subscribe to a plan (or start its free trial, when it has one). Calls to an API you are not subscribed to return `401`.

## URL format

```text
https://zylalabs.com/api/{api_id}/{api_name}/{endpoint_id}/{endpoint_name}
```

The API page builds this URL for you in the **Endpoints** section, with the parameters of each endpoint and code samples in 15 programming languages (cURL, JavaScript, Node.js, Python, PHP, Java, Go, C# and more). Copy it from there instead of building it by hand.

## Query parameters (GET)

```bash
curl 'https://zylalabs.com/api/{api_id}/{api_name}/{endpoint_id}/{endpoint_name}?email=john@example.com' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

```javascript
const res = await fetch(
  'https://zylalabs.com/api/{api_id}/{api_name}/{endpoint_id}/{endpoint_name}?email=john@example.com',
  { headers: { Authorization: `Bearer ${process.env.ZYLA_API_KEY}` } }
);
const data = await res.json();
```

```python
import os, requests

r = requests.get(
    "https://zylalabs.com/api/{api_id}/{api_name}/{endpoint_id}/{endpoint_name}",
    params={"email": "john@example.com"},
    headers={"Authorization": f"Bearer {os.environ['ZYLA_API_KEY']}"},
)
print(r.status_code, r.json())
```

## JSON body (POST)

Use the method shown on the endpoint. A different method returns `401` with `Invalid method`.

```bash
curl -X POST 'https://zylalabs.com/api/{api_id}/{api_name}/{endpoint_id}/{endpoint_name}' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"text": "Hello world"}'
```

## Response headers

Every successful response includes your usage, so you can throttle on your side:

| Header | Meaning |
|---|---|
| `X-Zyla-API-Calls-Monthly-Used` | Calls used in the current billing cycle of this subscription |
| `X-Zyla-API-Calls-Monthly-Remaining` | Calls left in the cycle |
| `X-Zyla-API-Calls-Monthly-Limit` | Calls included in your plan |
| `X-Zyla-RateLimit-Remaining` | Requests left in the current minute |
| `X-Zyla-RateLimit-Reset-Seconds` | Seconds until the per-minute window resets |

The body is the provider's response, returned as is. For errors raised by the gateway itself (no subscription, limits, unknown endpoint), see [Plans, limits and errors](https://zylalabs.com/docs/plans-and-limits).


---
Source: https://zylalabs.com/docs/calling-apis
