Agent Y2 API
Stream Y2's preconfigured workspace-aware agent through native or OpenAI-compatible requests
Agent Y2 exposes the same preconfigured intelligence agent used by the Y2 copilot through two API-key-authenticated streaming endpoints. It uses the key's workspace, plan entitlements, chat credit budget, persisted thread history, and allowed Y2 tools.
Agent Y2 is not a model gateway
API callers cannot select an arbitrary model, replace the fixed system instructions, enable
onboarding mode, or attach files in v1. The model value on the OpenAI-compatible route is a Y2
routing alias, not model selection.
Choose an endpoint
Both endpoints use https://api.y2.dev/api/v1.
| Endpoint | Stream format | Choose it when |
|---|---|---|
POST /agent-y2/chat/stream | Vercel AI SDK UI message stream | Your client understands the native AI SDK protocol |
POST /chat/completions | OpenAI-style chat.completion.chunk server-sent events | Your client already consumes streaming chat completions |
The routes share the same Agent Y2-specific rate-limit pool. Switching formats does not create a second quota.
Create a scoped key
Open API Keys
In the workspace that should own the threads and tool actions, open Settings → Developers → API Keys.
Grant agent:y2
Create a dedicated key with the agent:y2 scope. New API-key creation requires Pro or Elite.
Existing Lite keys remain usable only with the scopes already granted to them.
Store the key on a trusted server
Send it as Authorization: Bearer $Y2_API_KEY. Do not put an Agent Y2 key in browser bundles,
prompts, metadata, logs, or public repositories.
Agent Y2 does not support x402. A 402 response from these routes describes plan, chat-credit, or
upstream-provider credit exhaustion; it is not a payment challenge.
Send a native request
curl -N -i "https://api.y2.dev/api/v1/agent-y2/chat/stream" \
-H "Authorization: Bearer $Y2_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "user",
"parts": [
{ "type": "text", "text": "What changed in cyber risk this week?" }
]
}
],
"metadata": {
"source": "customer_crm",
"externalThreadId": "case-123"
}
}'The response is an AI SDK UI message stream. API responses omit internal reasoning parts even though the in-app stream can include them.
Read the X-Thread-Id response header and store it. Continue the conversation by sending that ID
in the next native request body:
{
"threadId": "j57...",
"messages": [
{
"role": "user",
"parts": [{ "type": "text", "text": "Which entities should I watch next?" }]
}
]
}Send an OpenAI-compatible request
curl -N -i "https://api.y2.dev/api/v1/chat/completions" \
-H "Authorization: Bearer $Y2_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "y2-agent",
"stream": true,
"messages": [
{
"role": "user",
"content": "Summarize the latest Y2 platform capabilities."
}
]
}'The compatibility route requires stream: true. model is optional; when supplied, it must be
y2-agent or agent-y2. It emits a role chunk, text-delta chunks, a final chunk with
finish_reason: "stop", and data: [DONE].
To continue a conversation, pass threadId in the JSON body or send the prior ID in an
X-Thread-Id request header.
Compatibility fields do not change Agent Y2
System, developer, and tool messages are accepted so OpenAI-oriented clients can serialize their
transcript, but they are excluded from Agent Y2's model context. Extra OpenAI fields such as
temperature, max_tokens, and tool definitions are not part of the v1 contract and do not
configure the agent.
Understand thread context
| Request state | Context used by Agent Y2 |
|---|---|
No threadId | Creates an API-source thread and uses non-empty user and assistant text from the supplied transcript |
Existing threadId | Verifies the same user, API source, and workspace, then loads up to 40 persisted messages from that thread |
| Latest user message | Saved to the thread and used as the new prompt |
| System, developer, or tool transcript entries | Accepted where compatible but not used to override or extend the fixed prompt |
A thread created in the app cannot be continued through the API. A workspace-scoped API key also cannot continue a thread from another workspace.
The server returns 400 for an invalid ID shape, 404 for a missing thread, and 403 when the
thread exists outside the caller's allowed source, user, or workspace scope.
Available tools
The exact tool set is assembled for every request from current workspace entitlements.
| Tool category | Availability |
|---|---|
| Y2 documentation search | Always registered |
| Public briefing search and follow | Registered for standard Agent Y2 sessions |
| News search | Registered for standard sessions |
| Web search | Requires the workspace web-search entitlement |
| Profile creation and editing | Requires remaining custom-profile capability and metering context |
| OSINT search | Requires OSINT entitlement |
| Y2 Global Knowledge retrieval | Requires Chat entitlement; searches only authorized shared and key-workspace corpora |
| Cyber, FININT, markets, entity, incident, and investigation tools | Added according to the related intelligence entitlements |
| Image generation | Requires image-generation entitlement and a compatible selected agent path |
Tool availability does not guarantee that the agent will call a tool. Tool actions still enforce the underlying workspace permissions and resource limits.
Agent Y2 uses its existing agent:y2 scope when it invokes Y2 Global Knowledge. Do not add
intel:knowledge to an Agent Y2 key unless the same integration also calls the direct retrieval
endpoint. Direct retrieval and agent execution are separate least-privilege surfaces.
Metadata behavior
Both routes accept a strict metadata object:
{
"metadata": {
"source": "ops_console",
"externalUserId": "analyst-42",
"externalThreadId": "case-123"
}
}| Field | Maximum | Current behavior |
|---|---|---|
source | 128 characters | Accepted for compatibility; the thread source is still recorded as api |
externalUserId | 256 characters | Accepted but not currently persisted to the thread |
externalThreadId | 256 characters | Stored when Y2 creates a new thread; it does not replace the Y2 threadId |
Unknown metadata properties fail strict validation. Keep your own correlation log and never put secrets or full customer records in metadata.
Provider privacy controls
The current Agent Y2 executor selects chat models marked as Zero Data Retention capable and sends
OpenRouter provider options with zdr: true and data_collection: "deny".
These controls govern the external model request. Y2 still stores API-source threads, messages, request attribution, tool results, and usage records under Y2's product data lifecycle. See the Privacy Policy for the customer-facing data terms.
Rate limits and response headers
Agent Y2 applies these limits in addition to the API key's normal plan limits:
| Limit scope | Per minute | Per day |
|---|---|---|
| API key | 5 | 100 |
| User or workspace aggregate | 10 | 250 |
Inspect Retry-After, the normal X-RateLimit-* headers, and the
X-Y2-Agent-RateLimit-* headers. Successful streams also return X-Thread-Id, X-Y2-Agent: y2,
and X-Y2-Agent-Mode: copilot.
Error guide
| Status | Common cause | Response |
|---|---|---|
400 | Invalid JSON, missing latest user text, unsupported alias, invalid thread ID, or native modelId, isOnboarding, or attachments | Correct the request; do not retry unchanged |
401 | Missing, malformed, revoked, or invalid API key | Replace or rotate the credential |
402 | Subscription, monthly chat-credit, or upstream provider credit exhaustion | Check plan and chat usage; do not start x402 handling |
403 | Missing scope, no chat entitlement, blocked access, or unauthorized thread | Check key scope, workspace, plan, and thread origin |
404 | Supplied thread no longer exists | Start a new thread or correct the stored ID |
429 | Normal API or shared Agent Y2 limit exceeded | Back off for Retry-After seconds |
500 | Stream preparation or provider execution failed | Retry with backoff and retain X-Request-Id for support |