メインコンテンツへスキップ

概要

FIM One API は 2 つの認証方法をサポートしています:
  1. API キー — サービス間統合用のシンプルで長期有効なトークン
  2. JWT トークン — ユーザーログインからの短期有効なトークン (SSE エンドポイント用)
ほとんどの統合では API キー を使用する必要があります。

APIキー

APIキーはユーザーアカウントに紐付けられた長期間有効な認証情報です。以下の用途に最適です:
  • サーバー間統合
  • スケジュール済みスクリプトと自動化
  • FIM Oneにアクセスする外部アプリケーション

APIキーの作成

  1. FIM Oneポータルにログインします
  2. 設定 → APIキーに移動します
  3. APIキーを作成をクリックします
  4. 名前を入力します(例:「本番環境統合」)
  5. (オプション)スコープを設定してアクセスを制限します
  6. (オプション)有効期限を設定します
  7. 作成をクリックします
  8. キーをすぐにコピーしてください — 1回だけ表示されます
完全なキーは次のようになります:fim_your44characterkeystringhere(fim_プレフィックスで始まります)

APIキーの使用

AuthorizationヘッダーにBearer tokenとしてキーを含めます:
またはPythonの場合:

APIキーの機能

可視性: 各キーには以下が表示されます:
  • キープレフィックス (識別用の最初の8文字)
  • 作成日
  • 最後に使用されたタイムスタンプ
  • 総リクエスト数
  • アクティブステータス
  • 有効期限 (設定されている場合)
管理: 以下のことができます:
  • キーを削除せずに有効/無効にする
  • 自動有効期限を設定する
  • キーを完全に削除する
  • 使用パターンを追跡する

スコープ

スコープはAPIキーがアクセスできる範囲を制限します。スコープが設定されていない場合、キーはフルアクセス権を持ちます。 スコープを持つキーは、そのスコープが許可するエンドポイントのみを呼び出すことができます。その他のすべてのエンドポイントは 403 で応答します。これには /api/me/api-keys 下のAPIキー管理も含まれ、スコープなしのキーまたはサインインセッションが必要です。キーは自身のスコープより広いスコープを持つキーを作成することはできません。 利用可能なスコープ: スコープ付きのキーを作成する:

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

JWTトークンの取得

JWTトークンはWebポータルを通じてログインするか、認証エンドポイントを呼び出すと自動的に発行されます:
レスポンス:

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):

トークンリフレッシュ

アクセストークンは2時間後に期限切れになります。リフレッシュトークンを使用して、再度ログインせずに新しいアクセストークンを取得します:

セキュリティのベストプラクティス

APIキー

APIキーをバージョン管理にコミットしないでください。 これらはデータへの完全なアクセスを提供します。
  1. 環境変数に保存する:
    その後、コードで参照します:
  2. キーローテーションを使用する:
    • 新しいキーを作成する
    • アプリケーションを更新する
    • 古いキーを削除する
    • 四半期ごとに繰り返す
  3. 有効期限を設定する:
    • 一時的な統合には短期間のキーを使用する
    • 定期的に再認証を要求する
  4. スコープ付きキーを使用する:
    • 必要な場合を除き、「フルアクセス」キーを使用しない
    • 異なるサービス用に個別のキーを作成する
    • キーが侵害された場合のダメージを制限する
  5. 使用状況を監視する:
    • 「最後に使用された」タイムスタンプを確認する
    • リクエスト数を確認する
    • 未使用のキーを削除する

JWTトークン

  1. 短命に保つ: アクセストークンは2時間後に期限切れになります
  2. 安全な保存:
    • ブラウザ内: HttpOnlyクッキーを使用(localStorageより安全)
    • サーバー内: 安全なセッションストレージを使用
  3. ログに公開しない: トークンのプレフィックスのみをログに記録し、完全なトークンは記録しないでください
  4. HTTPSのみを使用: 暗号化されていない接続でトークンを送信しないでください

レート制限

キーごとのレート制限は将来のリリースで予定されています。現在のところ、キーごとのリクエスト制限は実施されていません。

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:

環境変数のセットアップ

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