Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/smallestai/atoms/realtime/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def register_call(
1. Call this endpoint with your API key and the `agent_id` (plus optional
`mode` and per-call `variables`). All session configuration is fixed
here — it is baked into the returned token.
2. Open a WebSocket to `wss://api.smallest.ai/atoms/v1/agent/connect?token=<access_token>`.
2. Open the returned `websocket_url`, appending `?token=<access_token>`.
If an older server omits it, use the WebSocket endpoint for the same API region.
No `agent_id`, `mode`, or `variables` query params are needed on the
WebSocket — they come from the token.

Expand Down Expand Up @@ -136,7 +137,8 @@ async def register_call(
1. Call this endpoint with your API key and the `agent_id` (plus optional
`mode` and per-call `variables`). All session configuration is fixed
here — it is baked into the returned token.
2. Open a WebSocket to `wss://api.smallest.ai/atoms/v1/agent/connect?token=<access_token>`.
2. Open the returned `websocket_url`, appending `?token=<access_token>`.
If an older server omits it, use the WebSocket endpoint for the same API region.
No `agent_id`, `mode`, or `variables` query params are needed on the
WebSocket — they come from the token.

Expand Down
6 changes: 4 additions & 2 deletions src/smallestai/atoms/realtime/raw_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def register_call(
1. Call this endpoint with your API key and the `agent_id` (plus optional
`mode` and per-call `variables`). All session configuration is fixed
here — it is baked into the returned token.
2. Open a WebSocket to `wss://api.smallest.ai/atoms/v1/agent/connect?token=<access_token>`.
2. Open the returned `websocket_url`, appending `?token=<access_token>`.
If an older server omits it, use the WebSocket endpoint for the same API region.
No `agent_id`, `mode`, or `variables` query params are needed on the
WebSocket — they come from the token.

Expand Down Expand Up @@ -190,7 +191,8 @@ async def register_call(
1. Call this endpoint with your API key and the `agent_id` (plus optional
`mode` and per-call `variables`). All session configuration is fixed
here — it is baked into the returned token.
2. Open a WebSocket to `wss://api.smallest.ai/atoms/v1/agent/connect?token=<access_token>`.
2. Open the returned `websocket_url`, appending `?token=<access_token>`.
If an older server omits it, use the WebSocket endpoint for the same API region.
No `agent_id`, `mode`, or `variables` query params are needed on the
WebSocket — they come from the token.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class RegisterCallRealtimeResponseData(UncheckedBaseModel):
WebSocket.
"""

websocket_url: typing.Optional[str] = pydantic.Field(default=None)
"""
Region-correct WebSocket endpoint for this token, without query parameters.
Append the access_token as the token query parameter. Older servers may omit it.
"""

expires_in: typing.Optional[int] = pydantic.Field(default=None)
"""
Token lifetime in seconds.
Expand Down
39 changes: 39 additions & 0 deletions tests/custom/test_register_call_websocket_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import httpx
import pytest

from smallestai import AsyncSmallestAI, SmallestAI
from smallestai.atoms.realtime.types.register_call_realtime_response_data import RegisterCallRealtimeResponseData


@pytest.mark.parametrize("websocket_url", [None, "wss://us.example.com/atoms/v1/agent/connect"])
def test_register_call_parses_optional_regional_websocket_url(websocket_url):
payload = {"access_token": "wct_test", "expires_in": 30}
if websocket_url is not None:
payload["websocket_url"] = websocket_url
with httpx.Client(
transport=httpx.MockTransport(lambda _: httpx.Response(201, json={"status": True, "data": payload}))
) as http:
client = SmallestAI(api_key="test", httpx_client=http)
result = client.atoms.realtime.register_call(agent_id="agent")
assert result.data.websocket_url == websocket_url
assert result.data.access_token == "wct_test"


@pytest.mark.asyncio
async def test_async_register_call_preserves_regional_websocket_url():
target = "wss://us.example.com/atoms/v1/agent/connect"
async with httpx.AsyncClient(
transport=httpx.MockTransport(lambda _: httpx.Response(201, json={"data": {"websocket_url": target}}))
) as http:
client = AsyncSmallestAI(api_key="test", httpx_client=http)
result = await client.atoms.realtime.register_call(agent_id="agent")
assert result.data.websocket_url == target


def test_websocket_url_is_a_declared_optional_response_field():
# Extra-field parsing alone would hide a missing generated contract.
fields = getattr(RegisterCallRealtimeResponseData, "model_fields", None)
if fields is None:
fields = RegisterCallRealtimeResponseData.__fields__
assert "websocket_url" in fields
assert RegisterCallRealtimeResponseData().websocket_url is None
Loading