Skip to content

How to create and use API keys.

API Key Authentication

Finance API uses API key authentication. Every request must include a valid key in the F-API-KEY header.

HeaderExample
F-API-KEYF-API-KEY: fk-xxxxx

Creating an API Key

  1. Log in to the Admin Dashboard.
  2. Navigate to the API Keys page.
  3. Click Create Key and configure:
    • Name — A descriptive label for the key.
    • Daily Quota — Maximum requests per day (default: 1000).
    • Monthly Quota — Maximum requests per month (default: 10000).
    • Expires At — Optional expiration date.
  4. Copy the key immediately. The full key is shown only once.

Using an API Key

Include the key in the request header:

Terminal window
curl -H "F-API-KEY: fk-xxxxx" \
"https://finance-api.xp-java.workers.dev/api/v1/etf/basic?code=510300"

Key Security

  • Treat your API keys like passwords. Do not expose them in client-side code.
  • Do not commit keys to version control.
  • Rotate or revoke compromised keys immediately from the dashboard.
  • Keys are stored as SHA-256 hashes; the full value is never retrievable after creation.

Error Responses

Authentication errors return a JSON body with a non-zero code:

HTTPCodeMessageCause
4014010Missing headerF-API-KEY header is absent
4014010Invalid header formatBearer prefix required but missing (legacy mode)
4014011Invalid API key formatKey is too short or empty
4014012Invalid API keyKey does not exist in the database
4014013API key expiredKey has passed its expires_at date

Example error response:

{
"code": 4012,
"message": "Invalid API key"
}