إنشاء جلسة
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": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({agent_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'})
};
fetch('https://api.truthlocks.com/v1/agent-sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.truthlocks.com/v1/agent-sessions"
payload = { "agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a" }
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.truthlocks.com/v1/agent-sessions"
payload := strings.NewReader("{\n \"agent_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\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))
}{
"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
}جلسات وأدوات الوكيل
إنشاء جلسة
إنشاء جلسة مصادقة محددة بوقت لوكيل آلة مع رموز وصول محددة النطاق
POST
/
v1
/
agent-sessions
إنشاء جلسة
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": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({agent_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'})
};
fetch('https://api.truthlocks.com/v1/agent-sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.truthlocks.com/v1/agent-sessions"
payload = { "agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a" }
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.truthlocks.com/v1/agent-sessions"
payload := strings.NewReader("{\n \"agent_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\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))
}{
"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
}إنشاء جلسة
POST /v1/agent-sessions
ينشئ جلسة مصادقة جديدة لوكيل آلة. تربط الجلسة رمز وصول محدود الوقت ورمز تحديث بالوكيل، مع مجموعة نطاق صريحة يجب أن تكون مجموعة فرعية من النطاقات الممنوحة للوكيل.
يتم إرجاع token وrefresh_token فقط في استجابة الإنشاء. قم بتخزينها بأمان - لا يمكن استردادها لاحقًا.
يتم إرجاع حقلي
token و refresh_token مرة واحدة فقط في هذا
الاستجابة. قم بتخزينها في مدير أسرار آمن أو تخزين مشفر
فورًا. إذا فقدت، قم بإنهاء الجلسة وإنشاء جلسة جديدة.المصادقة
يتطلب رأسX-API-Key أو رمز Bearer JWT. يتم اشتقاق مساحة العمل من بيانات الاعتماد الموثقة؛ لا ترسل X-Tenant-ID.
الاستجابة
معرف جلسة MAIP بالتنسيق
maip-sess:<short-uuid>:<random-hex>.
استخدم هذا المعرف في استدعاءات API اللاحقة.رمز وصول مبهم لمصادقة طلبات API داخل هذه الجلسة.
سلسلة سداسية عشرية مكونة من 64 حرفًا. تُرجع مرة واحدة فقط.
رمز لتحديث الجلسة قبل انتهاء صلاحيتها. سلسلة سداسية عشرية مكونة من 64 حرفًا.
يتم إرجاعه مرة واحدة فقط.
مثال
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"
}
}'
دورة حياة الجلسة
Created (active) --> Refreshed (active) --> Expired (expired)
| |
+--> Terminated (terminated) |
| |
+--> Handed Off (handed_off) --> New Session (active)
الجسم
application/json

