Skip to main content
Sessions

セッションの作成

Identity と Template から Forward セッションを作成します。

POST /api/v1/forward/sessions Template のベースラインと Identity Config のオーバーライドをコンパイルしてから、ランタイム Session を起動することでセッションを作成します。

Headers

HeaderRequiredDescription
AuthorizationYesBearer <PAT または SAT>
Content-TypeYesapplication/json
Idempotency-KeyNo安全でないリクエスト向けの任意の冪等性キー。

Body parameters

ParameterTypeRequiredDescription
identity_idstringYesForward Identity ID。
template_idstringYesForward Template ID。
titlestringNoセッションのタイトル。
metadataobjectNoカスタムメタデータ。
configobjectNoセッションごとの構成オーバーライド。許可リストに含まれるフィールドのみ受け付けられます。
config.environment_variablesobjectNoキーと値のペアで指定するセッション環境変数。Template と Identity Config のコンパイル結果に追加マージされ、同じ名前の変数は Session レベルの値でベースレイヤーの値を上書きします。
resourcesarrayNoセッションレベルのリソース。現在はファイルマウント。
resources[].typestringYes when resources is usedリソースの種類。現在は file
resources[].file_idstringYes when resources is usedFiles API のファイル ID。
resources[].mount_pathstringNoエージェントコンテナ内のマウントパス。省略した場合、Forward がファイル名から導出します。
config.environment_variables のマージセマンティクス:
  • Forward は、Template の environment_variables ベースラインと Identity Config のオーバーライドレイヤーを先にコンパイルし、ベース環境変数を生成します。
  • リクエストで指定した key-value はベース環境変数に追加されます。新しいキーは追加され、同じ名前のキーは Session レベルの値でベースレイヤーの値を上書きします。
  • リクエストで指定しなかった変数は、Template と Identity Config のコンパイル結果に引き続き保持されます。

Example request

curl -s -X POST 'https://api.qoder.com/api/v1/forward/sessions' \
  -H "Authorization: Bearer $QODER_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "identity_id": "idn_xxx",
  "template_id": "tmpl_support",
  "title": "Customer support session",
  "metadata": {
    "source": "web",
    "biz_id": "ticket_123"
  },
  "config": {
    "environment_variables": {
      "API_KEY": "sk-xxx",
      "REGION": "cn-hangzhou"
    }
  },
  "resources": [
    {
      "type": "file",
      "file_id": "file_019e6a18dc09abcd",
      "mount_path": "/data/input.py"
    }
  ]
}'

Example response

HTTP 200 OK
{
  "id": "sess_xxx",
  "type": "session",
  "identity_id": "idn_xxx",
  "template": {
    "id": "tmpl_support",
    "type": "template",
    "name": "Support assistant",
    "model": "ultimate",
    "version": 3
  },
  "source_type": "api",
  "status": "idle",
  "title": "Customer support session",
  "metadata": {
    "source": "web"
  },
  "config": {
    "environment_variables": {
      "API_KEY": "sk-xxx"
    }
  },
  "stats": {
    "active_seconds": 0,
    "duration_seconds": 0
  },
  "usage": {
    "total_credits": 0
  },
  "archived_at": null,
  "created_at": "2026-06-22T10:00:00Z",
  "updated_at": "2026-06-22T10:00:00Z"
}

Response fields

FieldTypeDescription
idstringSession ID。
typestring常に session
identity_idstringForward Identity ID。
templateobjectTemplate の概要。
source_typestringセッションのソース。直接 API で作成した場合は api
statusstringidlerunningreschedulingcanceling、または terminated
archived_atstring|nullアーカイブのタイムスタンプ。
created_atstring作成日時のタイムスタンプ。
updated_atstring更新日時のタイムスタンプ。

Errors

HTTPTypeCodeTrigger
400invalid_request_errorinvalid_request_bodyリクエストボディが無効。
403permission_errortemplate_access_deniedIdentity が Template を使用できない。
404not_found_erroridentity_not_foundIdentity が存在しないか削除済み。
404not_found_errortemplate_not_foundTemplate が存在しない。
409conflict_erroridentity_disabledIdentity が無効化されている。
422invalid_request_errorruntime_config_invalid実効ランタイム構成が無効。
401authentication_errorauthentication_requiredPAT または SAT が無効または有効期限切れです。

Notes

  • source_type は Forward が割り当てるもので、作成リクエストでは受け付けられません。
  • incremental_streaming_enabled は後方互換性のために保持されているレガシーストリーミングの切り替えです。新規統合では推奨されず、作成後に変更できません。新規統合でストリーミング出力が必要な場合は、Session Event Stream の購読時に event_deltas[] を使用してください。このフィールドが true の場合、event_deltas[] は有効になりません。
  • アップロードするファイルは、resources で渡す前に Files API 上に存在している必要があります。
ベストプラクティス