{"id":2571,"library":"livekit-api","title":"LiveKit Server API","description":"livekit-api provides Python bindings for interacting with the LiveKit server API, enabling developers to manage rooms, participants, and access tokens for real-time video/audio applications. It's part of the broader LiveKit Python SDKs. The current version is 1.1.0, with frequent updates across the LiveKit SDK ecosystem.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/livekit/python-sdks/","tags":["real-time","video","audio","webrtc","api","livekit","rtc"],"install":[{"cmd":"pip install livekit-api","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Primary client for managing LiveKit rooms.","symbol":"RoomServiceClient","correct":"from livekit.api import RoomServiceClient"},{"note":"Class for generating JWT access tokens for participants.","symbol":"AccessToken","correct":"from livekit.api import AccessToken"},{"note":"Used to define permissions for access tokens.","symbol":"VideoGrants","correct":"from livekit.api import VideoGrants"},{"note":"Request object for creating new rooms.","symbol":"CreateRoomRequest","correct":"from livekit.api import CreateRoomRequest"}],"quickstart":{"code":"import os\nimport asyncio\nfrom livekit import api\n\nhost = os.environ.get(\"LIVEKIT_HOST\", \"http://localhost:7880\")\napi_key = os.environ.get(\"LIVEKIT_API_KEY\", \"devkey\")\napi_secret = os.environ.get(\"LIVEKIT_API_SECRET\", \"secret\")\n\nasync def main():\n    if not api_key or not api_secret:\n        print(\"LIVEKIT_API_KEY and LIVEKIT_API_SECRET must be set.\")\n        return\n\n    # Initialize LiveKit client\n    svc = api.RoomServiceClient(host, api_key, api_secret)\n\n    room_name = \"my-test-room\"\n    try:\n        room = await svc.create_room(\n            api.CreateRoomRequest(\n                name=room_name,\n                empty_timeout=60 * 10, # 10 minutes\n            )\n        )\n        print(f\"Room '{room.name}' created.\")\n    except api.ApiException as e:\n        if e.status == 409: # Room already exists\n            print(f\"Room '{room_name}' already exists.\")\n        else:\n            raise\n\n    # Generate an access token for a participant\n    token = api.AccessToken(api_key, api_secret) \\\n        .with_identity(\"user1\") \\\n        .with_name(\"Test User\") \\\n        .with_grants(api.VideoGrants(room_join=True, room=room_name)) \\\n        .to_jwt()\n\n    print(f\"Access Token: {token}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates how to create a LiveKit room and generate an access token for a participant using `livekit-api`. It uses environment variables for LiveKit host and credentials for security. The operations are asynchronous and should be run within an asyncio event loop."},"warnings":[{"fix":"Ensure all interactions with `livekit-api` services and methods are properly `await`ed within an `async` function, which is then run using `asyncio.run()`.","message":"The `livekit-api` library is built on `asyncio`. All service methods return awaitable objects. Calling these methods without `await` or outside an `async` context will lead to runtime errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always review `api.VideoGrants` (or other grant types like `api.RecorderGrants`) when generating tokens. Ensure `room_join=True` and any other necessary permissions (e.g., `can_publish`, `can_subscribe`) are set for the intended participant role.","message":"Access tokens generated by `api.AccessToken` require explicit grants (e.g., `api.VideoGrants`) to define what actions a participant can perform. Incorrectly configured grants are a common cause of 'permission denied' errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always retrieve sensitive credentials using environment variables (e.g., `os.environ.get('LIVEKIT_API_KEY')`) or a secure configuration management system.","message":"Hardcoding `LIVEKIT_HOST`, `LIVEKIT_API_KEY`, and `LIVEKIT_API_SECRET` directly in your code is a significant security risk and makes deployments brittle. These are sensitive credentials.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Regularly update `livekit-api` to the latest stable version. Consult the LiveKit server release notes and documentation for any required SDK version compatibility updates.","message":"Significant changes in the underlying LiveKit server API or protocol can lead to unexpected behavior or API breakage if the `livekit-api` SDK version is not kept reasonably up-to-date with the server version.","severity":"breaking","affected_versions":"All versions, especially older SDKs with newer servers"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}