Skip to main content

Overview

FIM One API supports two authentication methods:
  1. API Keys — Simple, long-lived tokens for service-to-service integration
  2. JWT Tokens — Short-lived tokens from user login (for SSE endpoints)
Most integrations should use API Keys.

API Keys

API keys are long-lived credentials tied to your user account. They’re ideal for:
  • Server-to-server integrations
  • Scheduled scripts and automation
  • External applications accessing FIM One

Creating an API Key

  1. Log in to your FIM One portal
  2. Go to Settings → API Keys
  3. Click Create API Key
  4. Enter a name (e.g., “Production Integration”)
  5. (Optional) Set scopes to limit access
  6. (Optional) Set an expiration date
  7. Click Create
  8. Copy the key immediately — it’s only shown once
The full key looks like: fim_your44characterkeystringhere (starts with fim_ prefix)

Using API Keys

Include the key in the Authorization header as a Bearer token:
Or in Python:

API Key Features

Visibility: Each key shows:
  • Key prefix (first 8 chars for identification)
  • Creation date
  • Last used timestamp
  • Total request count
  • Active status
  • Expiration date (if set)
Management: You can:
  • Enable/disable keys without deleting them
  • Set automatic expiration dates
  • Delete keys permanently
  • Track usage patterns

Scopes

Scopes limit what an API key can access. If no scopes are set, the key has full access. A key with scopes can call only the endpoints its scopes allow. Every other endpoint answers 403, including API key management under /api/me/api-keys, which needs a key without scopes or a signed-in session. A key can never create a key with broader scopes than its own. Available scopes: Create a key with scopes:

JWT Tokens

JWT tokens are short-lived and issued at login. They’re used for:
  • SSE Streaming Endpoints: Pass tokens in the request body for /api/react, /api/dag and /api/auto
  • Portal Session: Frontend authentication

Getting a JWT Token

JWT tokens are automatically issued when you log in through the web portal or call the authentication endpoint:
Response:

Two-factor authentication

When the account has two-factor authentication enabled, sign-in does not return tokens. POST /api/auth/login and POST /api/auth/login-with-code answer with a short-lived temporary token instead:
Send it with the TOTP code (or a backup code) to finish signing in. The response is the same token payload as a normal login:
The temporary token is valid for 5 minutes. Signing in through an OAuth provider (GitHub, Google, Discord, Feishu) stops at the same step: the callback hands the browser a 2FA challenge instead of tokens. After 5 incorrect codes within 15 minutes for the same account, the endpoint answers 429 with error_code 2fa_too_many_attempts; starting a new sign-in does not reset the count.

Using JWT for Streaming

For SSE endpoints, include the token in the request body. The field accepts a JWT access token or an API key (a scoped key needs the chat scope):
Or from JavaScript using fetch with a readable stream (the endpoint is POST-only, so native EventSource which only supports GET cannot be used):

Token Refresh

Access tokens expire after 2 hours. Use the refresh token to get a new access token without re-logging in:

Security Best Practices

API Keys

Never commit API keys to version control. They provide full access to your data.
  1. Store in environment variables:
    Then reference in code:
  2. Use key rotation:
    • Create a new key
    • Update your application
    • Delete the old key
    • Repeat quarterly
  3. Set expiration dates:
    • Use short-lived keys for temporary integrations
    • Require re-authentication periodically
  4. Use scoped keys:
    • Don’t use “full access” keys unless necessary
    • Create separate keys for different services
    • Limits damage if a key is compromised
  5. Monitor usage:
    • Check “last used” timestamps
    • Review request counts
    • Delete unused keys

JWT Tokens

  1. Keep short-lived: Access tokens expire after 2 hours
  2. Secure storage:
    • In browsers: use HttpOnly cookies (safer than localStorage)
    • In servers: use secure session storage
  3. Never expose in logs: Log only the token prefix, not the full token
  4. Use HTTPS only: Never send tokens over unencrypted connections

Rate Limits

Per-key rate limiting is planned for a future release. Currently there are no enforced per-key request limits.

Troubleshooting

Every error response has the shape {"detail", "error_code", "error_args"}. Errors raised while checking the Authorization header carry error_code: null; tell them apart by the status code and detail.

Invalid Token Error

Causes (401; detail is Invalid token, Invalid API key, API key is disabled or API key has expired):
  • API key prefix is wrong (must start with fim_)
  • Token is malformed or corrupted
  • API key has been deleted, disabled, or is past its expiration date
Solution: Verify your token format and re-generate if necessary

Unauthorized Error

Causes (401):
  • Token is missing from the request body (SSE endpoints return the body above)
  • No Authorization header provided (other endpoints answer Not authenticated with error_code: null)
Solution: Include a valid token in every request

Forbidden Error

Causes (403):
  • API key has scoped access and lacks the required scope (api_key_scope_denied)
  • The client address is refused by the instance’s IP rules (ip_not_allowed, see below)
  • The account is disabled (detail: Account disabled) or lacks the role the endpoint needs
Solution: Use a key with the appropriate scope or increase key privileges

IP Rules

Administrators can restrict API access by client address under admin Security → IP Rules. A request from an address that matches a deny rule, or that matches no allow rule when allow rules exist, is refused before authentication:
/api/version, /api/webhooks/ and CORS preflight requests are exempt. Behind a reverse proxy the instance must be told which proxy to trust (FORWARDED_ALLOW_IPS), otherwise every request appears to come from the proxy; see Environment Variables.

Expired Token

On the SSE endpoints, which read the token from the request body, the same condition returns error_code token_expired. Solution: Use the refresh token to get a new access token:

Environment Variable Setup

Python

Node.js

Bash

Support

For authentication issues:
  • Check the API Overview for response format details
  • Check that a token is still accepted with GET /api/auth/me
  • Contact support if you believe a key has been compromised