TypeScript SDK
import { Client } from "@notionhq/client"
const notion = new Client({ auth: process.env.NOTION_API_KEY })
// Start a session by omitting session_id
const session = await notion.sessions.update({
agent_id: "1f0c7c06-781b-4987-9986-5c8dd3028013",
message: "What can you help me with?"
})
// Continue it by passing the session_id back
const followUp = await notion.sessions.update({
session_id: session.id,
message: "Summarize that as bullet points."
})curl --request POST \
--url https://api.notion.com/v1/sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Notion-Version: <notion-version>' \
--data '
{
"message": "<string>",
"agent_id": "<string>",
"session_id": "<string>",
"attachments": [
{
"file_upload": {
"id": "<string>"
},
"type": "file_upload",
"name": "<string>"
}
],
"metadata": {},
"prompt_context": "<string>"
}
'import requests
url = "https://api.notion.com/v1/sessions"
payload = {
"message": "<string>",
"agent_id": "<string>",
"session_id": "<string>",
"attachments": [
{
"file_upload": { "id": "<string>" },
"type": "file_upload",
"name": "<string>"
}
],
"metadata": {},
"prompt_context": "<string>"
}
headers = {
"Notion-Version": "<notion-version>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.notion.com/v1/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([
'message' => '<string>',
'agent_id' => '<string>',
'session_id' => '<string>',
'attachments' => [
[
'file_upload' => [
'id' => '<string>'
],
'type' => 'file_upload',
'name' => '<string>'
]
],
'metadata' => [
],
'prompt_context' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Notion-Version: <notion-version>"
],
]);
$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.notion.com/v1/sessions"
payload := strings.NewReader("{\n \"message\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"session_id\": \"<string>\",\n \"attachments\": [\n {\n \"file_upload\": {\n \"id\": \"<string>\"\n },\n \"type\": \"file_upload\",\n \"name\": \"<string>\"\n }\n ],\n \"metadata\": {},\n \"prompt_context\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Notion-Version", "<notion-version>")
req.Header.Add("Authorization", "Bearer <token>")
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.notion.com/v1/sessions")
.header("Notion-Version", "<notion-version>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"message\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"session_id\": \"<string>\",\n \"attachments\": [\n {\n \"file_upload\": {\n \"id\": \"<string>\"\n },\n \"type\": \"file_upload\",\n \"name\": \"<string>\"\n }\n ],\n \"metadata\": {},\n \"prompt_context\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.notion.com/v1/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Notion-Version"] = '<notion-version>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"message\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"session_id\": \"<string>\",\n \"attachments\": [\n {\n \"file_upload\": {\n \"id\": \"<string>\"\n },\n \"type\": \"file_upload\",\n \"name\": \"<string>\"\n }\n ],\n \"metadata\": {},\n \"prompt_context\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"object": "session",
"id": "<string>",
"agent_id": "<string>",
"title": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"required_actions": [
{
"action_id": "<string>",
"title": "<string>",
"options": [
{
"label": "<string>"
}
]
}
],
"error": {
"code": "<string>",
"message": "<string>",
"retryable": true
}
}{
"object": "error",
"message": "<string>",
"status": 400,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "unauthorized",
"status": 401,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"status": 403,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"status": 404,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "row_limit_exceeded",
"status": 406,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"status": 409,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "rate_limited",
"status": 429,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "internal_server_error",
"status": 500,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "service_unavailable",
"status": 503,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "gateway_timeout",
"status": 504,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "service_overload",
"status": 529,
"additional_data": {}
}Agents
Create or update a session
Start a session, send a message, submit an action, or stream a session turn.
POST
/
v1
/
sessions
TypeScript SDK
import { Client } from "@notionhq/client"
const notion = new Client({ auth: process.env.NOTION_API_KEY })
// Start a session by omitting session_id
const session = await notion.sessions.update({
agent_id: "1f0c7c06-781b-4987-9986-5c8dd3028013",
message: "What can you help me with?"
})
// Continue it by passing the session_id back
const followUp = await notion.sessions.update({
session_id: session.id,
message: "Summarize that as bullet points."
})curl --request POST \
--url https://api.notion.com/v1/sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Notion-Version: <notion-version>' \
--data '
{
"message": "<string>",
"agent_id": "<string>",
"session_id": "<string>",
"attachments": [
{
"file_upload": {
"id": "<string>"
},
"type": "file_upload",
"name": "<string>"
}
],
"metadata": {},
"prompt_context": "<string>"
}
'import requests
url = "https://api.notion.com/v1/sessions"
payload = {
"message": "<string>",
"agent_id": "<string>",
"session_id": "<string>",
"attachments": [
{
"file_upload": { "id": "<string>" },
"type": "file_upload",
"name": "<string>"
}
],
"metadata": {},
"prompt_context": "<string>"
}
headers = {
"Notion-Version": "<notion-version>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.notion.com/v1/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([
'message' => '<string>',
'agent_id' => '<string>',
'session_id' => '<string>',
'attachments' => [
[
'file_upload' => [
'id' => '<string>'
],
'type' => 'file_upload',
'name' => '<string>'
]
],
'metadata' => [
],
'prompt_context' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Notion-Version: <notion-version>"
],
]);
$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.notion.com/v1/sessions"
payload := strings.NewReader("{\n \"message\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"session_id\": \"<string>\",\n \"attachments\": [\n {\n \"file_upload\": {\n \"id\": \"<string>\"\n },\n \"type\": \"file_upload\",\n \"name\": \"<string>\"\n }\n ],\n \"metadata\": {},\n \"prompt_context\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Notion-Version", "<notion-version>")
req.Header.Add("Authorization", "Bearer <token>")
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.notion.com/v1/sessions")
.header("Notion-Version", "<notion-version>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"message\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"session_id\": \"<string>\",\n \"attachments\": [\n {\n \"file_upload\": {\n \"id\": \"<string>\"\n },\n \"type\": \"file_upload\",\n \"name\": \"<string>\"\n }\n ],\n \"metadata\": {},\n \"prompt_context\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.notion.com/v1/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Notion-Version"] = '<notion-version>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"message\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"session_id\": \"<string>\",\n \"attachments\": [\n {\n \"file_upload\": {\n \"id\": \"<string>\"\n },\n \"type\": \"file_upload\",\n \"name\": \"<string>\"\n }\n ],\n \"metadata\": {},\n \"prompt_context\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"object": "session",
"id": "<string>",
"agent_id": "<string>",
"title": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"required_actions": [
{
"action_id": "<string>",
"title": "<string>",
"options": [
{
"label": "<string>"
}
]
}
],
"error": {
"code": "<string>",
"message": "<string>",
"retryable": true
}
}{
"object": "error",
"message": "<string>",
"status": 400,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "unauthorized",
"status": 401,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"status": 403,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"status": 404,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "row_limit_exceeded",
"status": 406,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"status": 409,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "rate_limited",
"status": 429,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "internal_server_error",
"status": 500,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "service_unavailable",
"status": 503,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "gateway_timeout",
"status": 504,
"additional_data": {}
}{
"object": "error",
"message": "<string>",
"code": "service_overload",
"status": 529,
"additional_data": {}
}Omit
session_id to start a session, or provide one to add a message or submit a required action to an existing session.
Stream a session turn
Send the same request withAccept: text/event-stream to receive server-sent events instead of a JSON session response. Streaming supports replaying an event with continue_from; that field is only valid with the SSE response.
curl --request POST "https://api.notion.com/v1/sessions" \
--header "Authorization: Bearer $NOTION_TOKEN" \
--header "Notion-Version: 2026-03-11" \
--header "Accept: text/event-stream" \
--header "Content-Type: application/json" \
--data '{"agent_id":"<agent-id>","message":"Summarize this week’s work."}'
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
The API version to use for this request. The latest version is 2026-03-11.
Available options:
2026-03-11 Body
application/json
- Update session request
- Update session request
- Update session request
Exactly one mode: append a message, answer pending actions, or replay from an event.
Response
Always session
Allowed value:
"session"One of: queued, in_progress, requires_action, completed, failed, canceled, terminated
Available options:
queued, in_progress, requires_action, completed, failed, canceled, terminated Maximum array length:
100Show child attributes
Show child attributes
Show child attributes
Show child attributes
⌘I