Developers

Login API key

Log in with an API key and get a session for the trading gateway.

On this page

URLs on this page: Testnet (chain ID 326). Other code on this page doesn't change: it stays on testnet until you switch it in your code. Tutorials, signing cases and live tools always use testnet.

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

SDKConfigure the client with an API key; raw edge login is not a generated client method
HTTPPOST https://edge.testnet.grvt.io/auth/api_key/login (login is served by the edge host, not the trading gateway)
WebSocketnot available (edge is HTTP only)
AuthNone
Contract idedge.api_key_login

Request

Body type EdgeApiKeyLoginRequest.

  • api_keystringrequired#
    The API key created in the Grvt UI.

Response

Body type EdgeLoginResponse.

  • statusstringrequired#
    "success" on success.
  • locationstringrequired#
    Always empty for API callers.
  • funding_account_addressstring (0x address)required#
    Funding (main) account the key belongs to.
  • sub_account_iduint64optional#
    Set only when the key was created for a trading (sub) account.

Errors

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

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

Example

Example code
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:

curl -sS -D - "https://edge.testnet.grvt.io/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.

esc

↑ ↓ move↵ open⇧↵ open .mdTry an error code like 2002

Keyboard shortcuts

⌘ K
Search the docs
/
Search
l
Next code language (Python → TypeScript → Go → Rust → curl → WebSocket)
j / k
Next / previous page
t
Light / dark theme
?
This help
Esc
Close dialogs and drawers