Create Session
curl --request POST \
--url https://api.truthlocks.com/v1/agent-sessions \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"agent_id": "550e8400-e29b-41d4-a716-446655440000",
"scopes": [
"datasets:read"
],
"ttl_seconds": 1800
}
'import requests
url = "https://api.truthlocks.com/v1/agent-sessions"
payload = {
"agent_id": "550e8400-e29b-41d4-a716-446655440000",
"scopes": ["datasets:read"],
"ttl_seconds": 1800
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_id: '550e8400-e29b-41d4-a716-446655440000',
scopes: ['datasets:read'],
ttl_seconds: 1800
})
};
fetch('https://api.truthlocks.com/v1/agent-sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.truthlocks.com/v1/agent-sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => '550e8400-e29b-41d4-a716-446655440000',
'scopes' => [
'datasets:read'
],
'ttl_seconds' => 1800
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.truthlocks.com/v1/agent-sessions"
payload := strings.NewReader("{\n \"agent_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"scopes\": [\n \"datasets:read\"\n ],\n \"ttl_seconds\": 1800\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.truthlocks.com/v1/agent-sessions")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"scopes\": [\n \"datasets:read\"\n ],\n \"ttl_seconds\": 1800\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.truthlocks.com/v1/agent-sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"scopes\": [\n \"datasets:read\"\n ],\n \"ttl_seconds\": 1800\n}"
response = http.request(request)
puts response.read_body{
"session_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"token": "<string>",
"scopes": [
"<string>"
],
"status": "active",
"metadata": {},
"expires_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"terminated_at": "2023-11-07T05:31:56Z"
}{
"code": "AUTH_REQUIRED",
"message": "Authentication required",
"http_status": 401
}{
"code": "AUTH_REQUIRED",
"message": "Authentication required",
"http_status": 401
}{
"code": "AUTH_REQUIRED",
"message": "Authentication required",
"http_status": 401
}{
"code": "AUTH_REQUIRED",
"message": "Authentication required",
"http_status": 401
}Agent Sessions & Tools
Create Session
Create a time-bound authenticated session for a machine agent with scoped access tokens
POST
/
v1
/
agent-sessions
Create Session
curl --request POST \
--url https://api.truthlocks.com/v1/agent-sessions \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"agent_id": "550e8400-e29b-41d4-a716-446655440000",
"scopes": [
"datasets:read"
],
"ttl_seconds": 1800
}
'import requests
url = "https://api.truthlocks.com/v1/agent-sessions"
payload = {
"agent_id": "550e8400-e29b-41d4-a716-446655440000",
"scopes": ["datasets:read"],
"ttl_seconds": 1800
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_id: '550e8400-e29b-41d4-a716-446655440000',
scopes: ['datasets:read'],
ttl_seconds: 1800
})
};
fetch('https://api.truthlocks.com/v1/agent-sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.truthlocks.com/v1/agent-sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'agent_id' => '550e8400-e29b-41d4-a716-446655440000',
'scopes' => [
'datasets:read'
],
'ttl_seconds' => 1800
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.truthlocks.com/v1/agent-sessions"
payload := strings.NewReader("{\n \"agent_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"scopes\": [\n \"datasets:read\"\n ],\n \"ttl_seconds\": 1800\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.truthlocks.com/v1/agent-sessions")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"agent_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"scopes\": [\n \"datasets:read\"\n ],\n \"ttl_seconds\": 1800\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.truthlocks.com/v1/agent-sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"scopes\": [\n \"datasets:read\"\n ],\n \"ttl_seconds\": 1800\n}"
response = http.request(request)
puts response.read_body{
"session_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"token": "<string>",
"scopes": [
"<string>"
],
"status": "active",
"metadata": {},
"expires_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"terminated_at": "2023-11-07T05:31:56Z"
}{
"code": "AUTH_REQUIRED",
"message": "Authentication required",
"http_status": 401
}{
"code": "AUTH_REQUIRED",
"message": "Authentication required",
"http_status": 401
}{
"code": "AUTH_REQUIRED",
"message": "Authentication required",
"http_status": 401
}{
"code": "AUTH_REQUIRED",
"message": "Authentication required",
"http_status": 401
}Create Session
POST /v1/agent-sessions
Creates a new authenticated session for a machine agent. The session binds a time-limited access token and refresh token to the agent, with an explicit scope set that must be a subset of the agent’s granted scopes.
The token and refresh_token are returned only in the creation response. Store them securely — they cannot be retrieved later.
The
token and refresh_token fields are only returned once in this
response. Store them in a secure secrets manager or encrypted storage
immediately. If lost, terminate the session and create a new one.Authentication
RequiresX-API-Key header or Bearer JWT token. Tenant-scoped via X-Tenant-ID.
Request Body
string
required
The MAIP agent identifier for which to create the session (e.g.,
maip:t1234567:01HYX3KPZQ7RJGBN0WFMV8SDEH). The agent must exist and be in
"active" status.string[]
Scopes for this session. Must be a subset of the agent’s assigned scopes
(scope narrowing). If omitted, inherits all of the agent’s scopes.
integer
Session lifetime in minutes. Range: 1 to 1440 (24 hours). Default:
60 (1
hour). Sessions cannot exceed the 24-hour maximum TTL.object
Arbitrary session metadata. Useful for tracking purpose, environment, or
orchestration context.
Response
object
The created session object containing:
string
Internal UUID primary key.
string
MAIP session identifier in format
maip-sess:<short-uuid>:<random-hex>.
Use this ID in subsequent API calls.string
The agent this session belongs to.
string
Session status. Always
"active" on creation.string[]
The effective scopes for this session.
object
Session metadata.
string
ISO 8601 expiration timestamp.
string
ISO 8601 creation timestamp.
string
ISO 8601 last-updated timestamp.
string
Opaque access token for authenticating API requests within this session.
64-character hex string. Returned only once.
string
Token for refreshing the session before expiry. 64-character hex string.
Returned only once.
Example
curl -X POST https://api.truthlocks.com/v1/agent-sessions \
-H "X-API-Key: tl_live_..." \
-H "Content-Type: application/json" \
-d '{
"agent_id": "maip:t1234567:01HYX3KPZQ7RJGBN0WFMV8SDEH",
"scopes": ["data:read", "tool:search.web"],
"ttl_minutes": 120,
"metadata": {
"purpose": "customer-inquiry-batch-2026-04-06",
"orchestrator": "support-pipeline-v2"
}
}'
Session Lifecycle
Created (active) --> Refreshed (active) --> Expired (expired)
| |
+--> Terminated (terminated) |
| |
+--> Handed Off (handed_off) --> New Session (active)
Authorizations
API key for machine-to-machine authentication
Body
application/json
Response
Session created

