Skip to main content
This API is in public beta

Prerequisites

A Custom Agent to chat with You need an existing Custom Agent because it’s the Agent you’ll chat with in this quickstart. In step 1, you’ll use the API to choose the Agent, then use its ID to start a chat in step 2. The API works with Custom Agents that already exist in the Notion app; it does not create them. To create a new Custom Agent, see Build a Custom Agent. A personal access token to authenticate requests This quickstart sends API requests on your behalf, so each request needs a personal access token (PAT). It lets you authenticate as yourself without setting up OAuth and carries your own access, so it can reach exactly the Custom Agents you can reach in Notion.
1
Open Personal access tokens in the Developer portal.
2
Select New token.
3
Enter a name, select the Notion API capability, and then select Create token. That capability covers the Agents API — there is nothing else to enable.
4
Copy the token and save it somewhere secure. You won’t be able to see it again.
Set the token as an environment variable so you can use it in the examples below. This lasts for your current terminal session — run it again if you open a new window.

Step 1: Pick a Custom Agent

Pick the Custom Agent you want to chat with. It can be the Custom Agent you created for this quickstart or an existing Custom Agent in your workspace that you can access. Use Query agents to find it. The example below narrows results to Custom Agents you created. Remove the created_by filter to choose another Custom Agent you can access.
curl
You get back a list of your Custom Agents, most recently created first:
Response
Copy the id of the Custom Agent you chose — that’s what you’ll chat with. Save it as an environment variable too:

Step 2: Start a new Agent chat

Send your agent a message by creating a session with Create or update a session. A session is one conversation: you create it with the first message, then keep sending to the same session_id to continue.
curl
The response is the new session:
Response
Save the session ID so the follow-up requests can use it:

Step 3: Read the Agent reply

The agent works asynchronously, so the session comes back as queued. Poll Retrieve a session until the status leaves queued and in_progress:
curl
Stream the response instead. To watch the turn as it happens instead of polling, send the same create request with Accept: text/event-stream. See Create or update a session. Once the status is completed, read the Agent reply from the session’s event history with Query session events:
curl
The agent’s answer comes back as an agent.message event:
Response
That’s a full round trip: you sent a message to a Custom Agent and read its response from the session events.

Common questions

Custom Agents are available on Business and Enterprise plans. Ask a workspace owner whether your workspace is on an eligible plan.
On Business and Enterprise plans, PAT creation is restricted by default. Ask a workspace owner to enable it in Settings → Connections.See Who can create PATs.
The curl examples are written for a Unix shell. In PowerShell, refer to the variables as $env:NOTION_API_KEY, $env:AGENT_ID, and $env:SESSION_ID.
Query agents also takes a free-text query that matches names and descriptions, along with filters on fields like id, agent_type, created_time, and connections. Sorting is available on created_time and last_run_at.

Next steps

You’ve found a Custom Agent through the API and started a chat. From here you can:
  • Keep the conversation going. Send another message to the same session_id for a follow-up, or submit an action the agent is waiting on.
  • Track what your agents cost. Read agent insights for credits used and runs completed per agent to build a usage dashboard.
  • Set guardrails. Give an agent a credit limit, or disable it when something looks wrong.
  • Batch manage agent. Apply status, credit-limit, and delete operations in a single asynchronous batch.
See the Overview for the full set of endpoints.