Create scoped, time-limited tokens that bind an agent to a specific task with context.
Task sessions are short-lived tokens that connect an agent’s identity to a specific task. They carry context (like a customer ID or ticket number) that policies can reference to scope access.
In the MCP Inspector, add both headers before connecting. MCP clients and SDKs include these headers in the transport configuration.The gateway resolves the task session and makes the task context available during policy evaluation.
When you create a task session, the gateway validates the context field against the task’s JSON Schema. If the context doesn’t match, the session is rejected with a 400 error.
// Task schema requires ticket_id (string) and customer_id (string)// This context is valid:{ "ticket_id": "TICKET-123", "customer_id": "cust_456" }// This context is invalid (missing required field):{ "ticket_id": "TICKET-123" }// → 400 Bad Request: context validation failed
An agent can have multiple active task sessions simultaneously
Task sessions are tied to both the identity and the task definition
The maximum TTL is 24 hours to prevent long-lived access tokens
Both the bearer token and task token must be valid for a request to succeed
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Devctrl","colors":{"primary":"#081B19","light":"#5effa8","dark":"#081B19"},"logo":"https://mintcdn.com/devctrl/ATpaLzWfWMOsSjGc/logo/logo.svg?fit=max\u0026auto=format\u0026n=ATpaLzWfWMOsSjGc\u0026q=85\u0026s=bfd24c0ce08ded78b0739973c8dbbc8f","favicon":"https://mintcdn.com/devctrl/fFAJI_JPxI6vTcVN/favicon.svg?fit=max\u0026auto=format\u0026n=fFAJI_JPxI6vTcVN\u0026q=85\u0026s=fdb78023585ae86c53facf9a747b178b","api":{"playground":{"proxy":false}},"appearance":{"default":"dark","strict":true},"background":{"color":{"dark":"#000000"}},"navbar":{"links":[],"primary":{"type":"button","label":"Get Started","href":"https://console.devctrl.ai"}},"fonts":{"family":"Geist","weight":400,"format":"woff2"},"styling":{"eyebrows":"breadcrumbs","latex":true},"banner":{"content":"Devctrl is currently in private beta.","dismissible":true},"thumbnails":{"background":"https://mintcdn.com/devctrl/fFAJI_JPxI6vTcVN/favicon.svg?fit=max\u0026auto=format\u0026n=fFAJI_JPxI6vTcVN\u0026q=85\u0026s=fdb78023585ae86c53facf9a747b178b","fonts":{"family":"Geist"}},"interaction":{"drilldown":true},"metadata":{"timestamp":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"devctrl","hasAudioNarration":false,"actualSubdomain":"devctrl","customDomains":["docs.devctrl.ai"],"gitSource":{"type":"github","owner":"devctrl-ai","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6a21dcd170c69447c72614df","collectionId":"02eb4358-5a5b-4ad3-a4ae-ffa85d9dca45","schemaVersion":"v2"},"feedback":{"thumbs":true},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6ae954ab62209e0b20b5c31a:success","clientVersion":"0.0.4054","searchFilterCounts":[{"language":"default","tag":"Documentation","count":23},{"language":"default","tag":"Console Guide","count":8},{"language":"default","tag":"Core Concepts","count":6},{"language":"default","tag":"Gateway","count":3},{"language":"default","tag":"Get Started","count":3},{"language":"default","tag":"Policies","count":3}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":true},"customCss":[],"page":{"pagePath":"gateway/task-sessions","slug":"/gateway/task-sessions","pageMetadata":{"title":"Task Sessions","description":"Create scoped, time-limited tokens that bind an agent to a specific task with context.","icon":"clock","href":"/gateway/task-sessions"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Create scoped, time-limited tokens that bind an agent to a specific task with context.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Tip}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Tip)_missingMdxReference(`Tip`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`Task sessions are short-lived tokens that connect an agent’s identity to a specific task. They carry context (like a customer ID or ticket number) that policies can reference to scope access.`}),`\n`,_jsx(Heading,{level:`2`,id:`create-a-task-session`,children:`Create a task session`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -X`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` POST`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` https://gateway.devctrl.ai/v1/tasks/sessions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Authorization: Bearer YOUR_CREDENTIAL_SECRET\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"taskId\": \"task_abc123\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"context\": {`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"ticket_id\": \"TICKET-123\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"customer_id\": \"cust_456\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"ttl\": 3600`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` }'`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`Request body:`})}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Field`}),_jsx(_components.th,{children:`Type`}),_jsx(_components.th,{children:`Required`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`taskId`})}),_jsx(_components.td,{children:`string`}),_jsx(_components.td,{children:`Yes`}),_jsx(_components.td,{children:`The task definition ID from the console`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`context`})}),_jsx(_components.td,{children:`object`}),_jsx(_components.td,{children:`Yes`}),_jsx(_components.td,{children:`Runtime context for this task instance. Must match the task’s context schema.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`ttl`})}),_jsx(_components.td,{children:`integer`}),_jsx(_components.td,{children:`No`}),_jsx(_components.td,{children:`Time-to-live in seconds. Default: 3600 (1 hour). Max: 86400 (24 hours).`})]})]})]}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`Response:`})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`5`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"taskToken\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"a1b2c3d4e5f6g7h8...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"tokenId\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ts_abc123\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"expiresAt\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"2026-04-10T15:00:00Z\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`use-a-task-session`,children:`Use a task session`}),`\n`,_jsxs(_components.p,{children:[`Include the task token in subsequent MCP requests using the `,_jsx(_components.code,{children:`X-Task-Token`}),` header alongside your `,_jsx(_components.code,{children:`Authorization`}),` header:`]}),`\n`,_jsx(CodeBlock,{numberOfLines:`3`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`3`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Authorization: Bearer YOUR_CREDENTIAL_SECRET`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`X-Task-Token: a1b2c3d4e5f6g7h8...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(_components.p,{children:[`In the `,_jsx(_components.a,{href:`https://github.com/modelcontextprotocol/inspector`,children:`MCP Inspector`}),`, add both headers before connecting. MCP clients and SDKs include these headers in the transport configuration.`]}),`\n`,_jsx(_components.p,{children:`The gateway resolves the task session and makes the task context available during policy evaluation.`}),`\n`,_jsx(Heading,{level:`2`,id:`get-the-current-session`,children:`Get the current session`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` https://gateway.devctrl.ai/v1/tasks/sessions/current`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Authorization: Bearer YOUR_CREDENTIAL_SECRET\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"X-Task-Token: a1b2c3d4e5f6g7h8...\"`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Returns the active session details including the task name, context, and expiry time.`}),`\n`,_jsx(Heading,{level:`2`,id:`delete-a-session`,children:`Delete a session`}),`\n`,_jsx(_components.p,{children:`End a task session early when the agent finishes its work:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -X`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` DELETE`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` https://gateway.devctrl.ai/v1/tasks/sessions/current`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Authorization: Bearer YOUR_CREDENTIAL_SECRET\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"X-Task-Token: a1b2c3d4e5f6g7h8...\"`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`This immediately invalidates the task token. Any subsequent requests using it will be rejected.`}),`\n`,_jsx(Tip,{children:_jsx(_components.p,{children:`Always delete task sessions when the agent finishes a task. This follows the principle of least privilege — don’t keep access open longer than needed.`})}),`\n`,_jsx(Heading,{level:`2`,id:`lifecycle`,children:`Lifecycle`}),`\n`,_jsx(CodeBlock,{numberOfLines:`9`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Create session Use session Session ends`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │ │ │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` ▼ ▼ ▼`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`POST /v1/tasks/sessions → X-Task-Token header → TTL expires`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │ │ or DELETE`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` │ │ │`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` └── Context validated └── Policies check └── Token invalidated`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` against schema task.context`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`2`,id:`context-validation`,children:`Context validation`}),`\n`,_jsxs(_components.p,{children:[`When you create a task session, the gateway validates the `,_jsx(_components.code,{children:`context`}),` field against the task’s JSON Schema. If the context doesn’t match, the session is rejected with a `,_jsx(_components.code,{children:`400`}),` error.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`7`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Task schema requires ticket_id (string) and customer_id (string)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// This context is valid:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{ `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"ticket_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"TICKET-123\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"customer_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"cust_456\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// This context is invalid (missing required field):`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{ `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"ticket_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"TICKET-123\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// → 400 Bad Request: context validation failed`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`notes`,children:`Notes`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`An agent can have multiple active task sessions simultaneously`}),`\n`,_jsx(_components.li,{children:`Task sessions are tied to both the identity and the task definition`}),`\n`,_jsx(_components.li,{children:`The maximum TTL is 24 hours to prevent long-lived access tokens`}),`\n`,_jsx(_components.li,{children:`Both the bearer token and task token must be valid for a request to succeed`}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Task Sessions","description":"Create scoped, time-limited tokens that bind an agent to a specific task with context.","icon":"clock","href":"/gateway/task-sessions"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Create a task session","slug":"create-a-task-session","depth":2,"children":[]},{"title":"Use a task session","slug":"use-a-task-session","depth":2,"children":[]},{"title":"Get the current session","slug":"get-the-current-session","depth":2,"children":[]},{"title":"Delete a session","slug":"delete-a-session","depth":2,"children":[]},{"title":"Lifecycle","slug":"lifecycle","depth":2,"children":[]},{"title":"Context validation","slug":"context-validation","depth":2,"children":[]},{"title":"Notes","slug":"notes","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"devctrl","siteName":"Devctrl","title":"Task Sessions - Devctrl","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-04-21T12:37:02.352Z","originalFileLocation":"gateway/task-sessions.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=\"dark\";if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"dark\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Create scoped, time-limited tokens that bind an agent to a specific task with context.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Devctrl\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Task Sessions - Devctrl\">\u003cmeta data-mint-head property=\"og:description\" content=\"Create scoped, time-limited tokens that bind an agent to a specific task with context.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Devctrl\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.devctrl.ai/gateway/task-sessions\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://devctrl.mintlify.app/_mintlify/api/og/v2?division=Gateway\u0026amp;title=Task+Sessions\u0026amp;description=Create+scoped%2C+time-limited+tokens+that+bind+an+agent+to+a+specific+task+with+context.\u0026amp;theme=ba6fff81f9aedc6eb94076e6\u0026amp;signature=be98497519787eee8fd5ff58d84d1639ede39d7cf4573e255d97794ed1635ed0\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Task Sessions - Devctrl\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Create scoped, time-limited tokens that bind an agent to a specific task with context.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://devctrl.mintlify.app/_mintlify/api/og/v2?division=Gateway\u0026amp;title=Task+Sessions\u0026amp;description=Create+scoped%2C+time-limited+tokens+that+bind+an+agent+to+a+specific+task+with+context.\u0026amp;theme=ba6fff81f9aedc6eb94076e6\u0026amp;signature=be98497519787eee8fd5ff58d84d1639ede39d7cf4573e255d97794ed1635ed0\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/devctrl/mGK0v6vxhkZZVE5O/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Devctrl\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#081B19\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.devctrl.ai/gateway/task-sessions\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/gateway/task-sessions.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.devctrl.ai/#organization\",\"name\":\"Devctrl\",\"url\":\"https://docs.devctrl.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/devctrl/ATpaLzWfWMOsSjGc/logo/logo.svg?fit=max\u0026auto=format\u0026n=ATpaLzWfWMOsSjGc\u0026q=85\u0026s=bfd24c0ce08ded78b0739973c8dbbc8f\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.devctrl.ai#website\",\"name\":\"Devctrl\",\"url\":\"https://docs.devctrl.ai\",\"publisher\":{\"@id\":\"https://docs.devctrl.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.devctrl.ai/gateway/task-sessions#webpage\",\"url\":\"https://docs.devctrl.ai/gateway/task-sessions\",\"name\":\"Task Sessions\",\"description\":\"Create scoped, time-limited tokens that bind an agent to a specific task with context.\",\"dateModified\":\"2026-04-21T12:37:02.352Z\",\"isPartOf\":{\"@id\":\"https://docs.devctrl.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.devctrl.ai/gateway/task-sessions#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.devctrl.ai/gateway/task-sessions#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Gateway\",\"item\":\"https://docs.devctrl.ai/gateway/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Task Sessions\",\"item\":\"https://docs.devctrl.ai/gateway/task-sessions\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.devctrl.ai/gateway/task-sessions#article\",\"headline\":\"Task Sessions\",\"name\":\"Task Sessions\",\"description\":\"Create scoped, time-limited tokens that bind an agent to a specific task with context.\",\"url\":\"https://docs.devctrl.ai/gateway/task-sessions\",\"mainEntityOfPage\":{\"@id\":\"https://docs.devctrl.ai/gateway/task-sessions#webpage\"},\"dateModified\":\"2026-04-21T12:37:02.352Z\",\"publisher\":{\"@id\":\"https://docs.devctrl.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.devctrl.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Devctrl\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Devctrl","nav":{"global":null,"tabs":[{"tab":"Documentation","groups":[{"group":"Get Started","pages":[{"title":"Introduction","icon":"0","href":"/introduction"},{"title":"Quickstart","icon":"bolt","href":"/quickstart"},{"title":"How It Works","icon":"cloud-question","mode":"wide","href":"/how-it-works"}]},{"group":"Core Concepts","pages":[{"title":"MCP Gateway","icon":"server","href":"/concepts/mcp-gateway"},{"title":"Task-Based Access Control","sidebarTitle":"TBAC","icon":"shield-check","href":"/concepts/task-based-access-control"},{"title":"Policies","icon":"shield","href":"/concepts/policies"},{"title":"Identities","icon":"id-card","href":"/concepts/identities"},{"title":"Tasks","icon":"list-check","href":"/concepts/tasks"},{"title":"Audit Log","icon":"clipboard-list","href":"/concepts/audit-log"}]},{"group":"Console Guide","pages":[{"title":"Projects","icon":"folder","href":"/console/projects"},{"title":"Register MCP Servers","sidebarTitle":"MCP Servers","icon":"server","href":"/console/register-mcp-servers"},{"title":"Manage Tools","sidebarTitle":"Tools","icon":"wrench","href":"/console/manage-tools"},{"title":"Create Identities","sidebarTitle":"Identities","icon":"id-card","href":"/console/create-identities"},{"title":"Define Tasks","sidebarTitle":"Tasks","icon":"list-check","href":"/console/define-tasks"},{"title":"Write Policies","sidebarTitle":"Write Policies","icon":"pencil","href":"/console/write-policies"},{"title":"Publish Policies","sidebarTitle":"Publish Policies","icon":"rocket","href":"/console/publish-policies"},{"title":"View Executions","sidebarTitle":"Executions","icon":"table","href":"/console/view-executions"}]},{"group":"Gateway","pages":[{"title":"Gateway Overview","sidebarTitle":"Overview","icon":"diagram-project","href":"/gateway/overview"},{"title":"Connect an Agent","sidebarTitle":"Connect an Agent","description":"Point any MCP-compatible AI agent at the Devctrl gateway.","icon":"plug","href":"/gateway/connect-an-agent"},{"title":"Task Sessions","icon":"clock","href":"/gateway/task-sessions"}]},{"group":"Policies","pages":[{"title":"CEL Expressions","sidebarTitle":"CEL Reference","description":"Reference guide for writing CEL policy expressions in Devctrl.","icon":"code","href":"/policies/cel-expressions"},{"title":"Policy Examples","sidebarTitle":"Examples","icon":"book-open","href":"/policies/examples"},{"title":"RBAC vs TBAC","icon":"scale-balanced","href":"/policies/rbac-vs-tbac"}]}]}]},"basePath":"","title":"Task Sessions - Devctrl","buildId":"dpl_345ReqzYaAjzS9QpeJemsKdb7KDj","deploymentId":"dpl_345ReqzYaAjzS9QpeJemsKdb7KDj","dynamics":[],"chunks":[]}