Prerequisites
- A LangSmith account with an Agent Builder agent
- A Personal Access Token (PAT) for authentication
- (SDK only) The LangGraph SDK installed:
Authentication
To authenticate with your agent’s Agent Builder deployment, provide a LangSmith Personal Access Token (PAT) to theapi_key argument when instantiating the LangGraph SDK client, or via the X-API-Key header. If using X-API-Key, you must also set the X-Auth-Scheme header to langsmith-api-key.
If the PAT you pass is not tied to the owner of the agent, your request will be rejected with a 404 Not Found error.
If the agent you’re trying to invoke is a and you’re not the owner, you can perform all the same operations as you would in the UI (read-only).
1. Get the agent ID and URL
To get your agent’sagent_id and api_url:
- In the LangSmith UI, navigate to your agent’s inbox.
- Next to the agent name, click the Edit Agent icon.
- Click the Settings icon in the top right corner.
- Click View code snippets to see pre-populated values for your agent.
agent_id and api_url with the values from your agent’s code snippets.
Create a .env file in your project root with your Personal Access Token:
.env
2. Fetch agent configuration
Verify your connection by fetching your agent’s configuration:- Python
- TypeScript
- cURL
Use a Personal Access Token (PAT) tied to your LangSmith account. Set the
X-Auth-Scheme header to langsmith-api-key for authentication. If you implemented custom authentication, pass the user’s token in headers so the agent can use user-scoped tools. See Add custom authentication.3. Invoke agent
The examples below show how to send a message to your agent and receive a response. You can use either a stateless run (no thread, no conversation history) or a stateful run (with a thread to maintain conversation history across multiple turns).Stateless run
A stateless run sends a single request and returns the full response. No conversation history is persisted. This is the simplest way to call your agent:- Python
- TypeScript
- cURL
Stateless streaming run
To stream the response as it is generated rather than waiting for the full result, use the streaming endpoint:- Python
- TypeScript
- cURL
Stateful run with a thread
To maintain conversation history across multiple interactions, first create a thread and then run your agent on it. Each subsequent run on the same thread has access to the full message history:- Python
- TypeScript
- cURL
REST API reference
The table below summarizes the key endpoints. Replace<API_URL> with your agent’s deployment URL.
| Operation | Method | Endpoint |
|---|---|---|
| Get agent info | GET | <API_URL>/assistants/<AGENT_ID> |
| Create a thread | POST | <API_URL>/threads |
| Run (wait for result) | POST | <API_URL>/runs/wait |
| Run (streaming) | POST | <API_URL>/runs/stream |
| Run on thread (wait) | POST | <API_URL>/threads/<THREAD_ID>/runs/wait |
| /langsmith/agent-server-api/thread-runs/create-run-stream-output | POST | <API_URL>/threads/<THREAD_ID>/runs/stream |
Content-Type: application/jsonX-Api-Key:your Personal Access TokenX-Auth-Scheme: langsmith-api-key
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.