Skip to content

Commit 2e85335

Browse files
committed
update readme to reflect LKAPI interfaces
will merge after api release
1 parent 357e5db commit 2e85335

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ async def main():
6565
asyncio.run(main())
6666
```
6767

68+
### Authentication
69+
70+
Authenticate with an API key and secret (recommended for backend use), or with a
71+
pre-signed token for client-side use, where the API secret must not be exposed.
72+
Any omitted value falls back to `LIVEKIT_URL`, `LIVEKIT_API_KEY`,
73+
`LIVEKIT_API_SECRET`, and `LIVEKIT_TOKEN`.
74+
75+
```python
76+
# API key & secret (backend)
77+
lkapi = api.LiveKitAPI("https://my-project.livekit.cloud", api_key="...", api_secret="...")
78+
79+
# pre-signed token (client-side); the token must already carry the grants for the calls
80+
lkapi = api.LiveKitAPI.with_token(my_token, "https://my-project.livekit.cloud")
81+
```
82+
6883
### Using other APIs
6984

7085
Services can be accessed via the LiveKitAPI object.
@@ -91,6 +106,38 @@ dispatch_svc = lkapi.agent_dispatch
91106
connector_svc = lkapi.connector
92107
```
93108

109+
### Error handling
110+
111+
A failed server API call raises `api.ServerError`, which exposes the error
112+
`code`, `message`, and any server-provided `metadata`.
113+
114+
```python
115+
try:
116+
await lkapi.room.create_room(api.CreateRoomRequest(name="my-room"))
117+
except api.ServerError as e:
118+
print(e.code, e.message)
119+
```
120+
121+
A failed SIP dial (e.g. the callee is busy or doesn't answer) raises
122+
`api.SipCallError`, a `ServerError` subclass that also exposes the SIP response
123+
status:
124+
125+
```python
126+
try:
127+
await lkapi.sip.create_sip_participant(api.CreateSIPParticipantRequest(
128+
sip_trunk_id="ST_...",
129+
sip_call_to="+15105550100",
130+
room_name="my-room",
131+
wait_until_answered=True,
132+
))
133+
except api.SipCallError as e:
134+
print(e) # e.g. "SIP call failed: 486 Busy Here (resource_exhausted)"
135+
if e.sip_status_code == 486:
136+
... # busy
137+
except api.ServerError as e:
138+
print(e.code, e.message) # any other API error
139+
```
140+
94141
## Using Real-time SDK
95142

96143
```shell

0 commit comments

Comments
 (0)