---
title: "Login API key"
description: "Log in with an API key and get a session for the trading gateway."
---

The response sets the `gravity` cookie and the `X-Grvt-Account-Id` header; send both on every authenticated call and on the WebSocket upgrade.

| | |
|---|---|
| SDK | Configure the client with an API key; raw edge login is not a generated client method |
| HTTP | `POST https://edge.<domain>/auth/api_key/login` (login is served by the edge host, not the trading gateway) |
| WebSocket | not available (edge is HTTP only) |
| Auth | None |
| Contract id | `edge.api_key_login` |

## Request

Body type `EdgeApiKeyLoginRequest`.

- `api_key` · string · required — The API key created in the Grvt UI.

## Response

Body type `EdgeLoginResponse`.

- `status` · string · required — "success" on success.
- `location` · string · required — Always empty for API callers.
- `funding_account_address` · string (0x address) · required — Funding (main) account the key belongs to.
- `sub_account_id` · uint64 · optional — Set only when the key was created for a trading (sub) account.

## Errors

Edge errors are not gateway error codes. Body: EdgeLoginError.

| HTTP | Meaning |
|---|---|
| 400 | invalid request body |
| 401 | Invalid Credentials |
| 403 | IP not whitelisted, country restricted, or account deactivated, closed or on hold |
| 500 | Internal Server Error |

## Example

```python
import os

from grvt import Grvt

# Login happens on the first authenticated call and is renewed before the cookie expires.
with Grvt(env=os.environ.get("GRVT_ENV", "testnet"), api_key=os.environ["GRVT_API_KEY"]) as client:
    print(client.get_sub_accounts())
```

Raw HTTP. `-D -` prints the response headers, which carry the cookie and account id:

```sh
curl -sS -D - "https://edge.$GRVT_DOMAIN/auth/api_key/login" \
  -H "Content-Type: application/json" \
  --data @- <<EOF
{"api_key": "$GRVT_API_KEY"}
EOF
```

From the response, take `gravity=...` from `Set-Cookie` into `GRVT_COOKIE` (value only) and `X-Grvt-Account-Id` into `GRVT_ACCOUNT_ID`.
