Sessions
List Sessions
Retrieve all sessions for the current user
GET
/
api
/
v1
/
sessions
List Sessions
curl --request GET \
--url https://api.example.com/api/v1/sessions \
--header 'X-API-Key: <x-api-key>'import requests
url = "https://api.example.com/api/v1/sessions"
headers = {"X-API-Key": "<x-api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-API-Key': '<x-api-key>'}};
fetch('https://api.example.com/api/v1/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.example.com/api/v1/sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-API-Key: <x-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"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/sessions"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-API-Key", "<x-api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/api/v1/sessions")
.header("X-API-Key", "<x-api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-API-Key"] = '<x-api-key>'
response = http.request(request)
puts response.read_body{
"status": "<string>",
"result": [
{
"session_id": "<string>",
"uri": "<string>",
"is_dir": true
}
],
"time": 123
}List all conversation sessions associated with the authenticated user.
Request
Headers
string
required
Your OpenViking API key for authentication
Response
string
Response status (
ok or error)array
number
Request processing time in seconds
Examples
curl -X GET http://localhost:1933/api/v1/sessions \
-H "X-API-Key: your-api-key"
import openviking as ov
# Initialize client
client = ov.OpenViking(path="./my_data")
client.initialize()
# List all sessions
sessions = client.ls("viking://session/")
for session in sessions:
print(f"Session: {session['name']}")
# Or use the dedicated method
sessions = client.list_sessions()
for session in sessions:
print(f"ID: {session['session_id']} - URI: {session['uri']}")
import requests
response = requests.get(
"http://localhost:1933/api/v1/sessions",
headers={"X-API-Key": "your-api-key"}
)
result = response.json()
for session in result['result']:
print(f"Session ID: {session['session_id']}")
Response Example
{
"status": "ok",
"result": [
{
"session_id": "a1b2c3d4",
"uri": "viking://session/alice/a1b2c3d4",
"is_dir": true
},
{
"session_id": "e5f6g7h8",
"uri": "viking://session/alice/e5f6g7h8",
"is_dir": true
}
],
"time": 0.1
}
Use Cases
List and Resume Sessions
import openviking as ov
client = ov.OpenViking(path="./my_data")
client.initialize()
# List all sessions
sessions = client.list_sessions()
if sessions:
# Resume the most recent session
latest_session_id = sessions[0]['session_id']
session = client.session(session_id=latest_session_id)
session.load()
print(f"Resumed session with {len(session.messages)} messages")
else:
# Create new session if none exist
session = client.session()
print(f"Created new session: {session.session_id}")
Session Management Dashboard
import openviking as ov
from datetime import datetime
client = ov.OpenViking(path="./my_data")
client.initialize()
sessions = client.list_sessions()
print(f"Total sessions: {len(sessions)}\n")
for sess in sessions:
session_id = sess['session_id']
details = client.get_session(session_id)
print(f"Session: {session_id}")
print(f" Messages: {details['message_count']}")
print(f" URI: {sess['uri']}")
print()
Related Endpoints
- Create Session - Create a new session
- Get Session - Get details for a specific session
- Delete Session - Remove a session
⌘I
List Sessions
curl --request GET \
--url https://api.example.com/api/v1/sessions \
--header 'X-API-Key: <x-api-key>'import requests
url = "https://api.example.com/api/v1/sessions"
headers = {"X-API-Key": "<x-api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-API-Key': '<x-api-key>'}};
fetch('https://api.example.com/api/v1/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.example.com/api/v1/sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-API-Key: <x-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"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/sessions"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-API-Key", "<x-api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/api/v1/sessions")
.header("X-API-Key", "<x-api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-API-Key"] = '<x-api-key>'
response = http.request(request)
puts response.read_body{
"status": "<string>",
"result": [
{
"session_id": "<string>",
"uri": "<string>",
"is_dir": true
}
],
"time": 123
}