Spaces & Audio
Access Twitter Spaces data including live and recorded audio rooms, participants, hosts, and recordings.
Overview
The Spaces endpoints provide comprehensive access to Twitter Spaces - live and scheduled audio conversations. You can retrieve Space details, search for Spaces, get participant lists, access recordings, and monitor live Spaces. These endpoints are essential for building applications that interact with Twitter's audio content.
Key Features
- Space Lookup: Get detailed information about any Space
- Live Spaces: Find currently live Spaces
- Scheduled Spaces: Discover upcoming Spaces
- Participant Management: Get hosts, speakers, and listeners
- Search: Search Spaces by topic, title, or host
- Recordings: Access Space recordings and playback URLs
- User Spaces: Get all Spaces for a specific user
- Real-Time Data: Access live participant counts and status
Authentication
All endpoints require authentication via the X-API-KEY header:
X-API-KEY: YOUR_API_KEYFor detailed authentication information, see our Authentication Guide.
Understanding Space States
Spaces can be in different states throughout their lifecycle. Understanding these states is crucial for building robust applications.
Space States
| State | Description | Characteristics |
|---|---|---|
| scheduled | Space is scheduled but not yet started | Has scheduled_start time, state: "scheduled" |
| live | Space is currently running | Has started_at time, state: "live", real-time participant count |
| ended | Space has finished | Has ended_at time, state: "ended", may have recording |
| cancelled | Space was cancelled before starting | state: "cancelled", no recording available |
State Transitions
scheduled → live → ended
↓
cancelled
Working with States
function getSpaceStatus(space) {
switch (space.state) {
case 'scheduled':
return {
status: 'Upcoming',
time: space.scheduled_start,
canJoin: false
};
case 'live':
return {
status: 'Live Now',
participants: space.participant_count,
canJoin: true
};
case 'ended':
return {
status: 'Ended',
endedAt: space.ended_at,
hasRecording: space.recording_available
};
case 'cancelled':
return {
status: 'Cancelled',
canJoin: false
};
}
}Endpoints
Get Space by ID
Retrieves detailed information about a specific Space, including its current state, participants, host information, and metadata.
Endpoint: GET /space/{space_id}
Path Parameters
| Name | Type | Required | Description |
|---|---|---|---|
space_id | string | Yes | The unique Space ID (e.g., "1abcdefghijklmno") |
Request Examples
curl --request GET \
--url 'https://<direct.gateway>/space/1abcdefghijklmno' \
--header 'X-API-KEY: YOUR_API_KEY'JavaScript:
const response = await fetch('https://<direct.gateway>/space/1abcdefghijklmno', {
headers: { 'X-API-KEY': 'YOUR_API_KEY' }
});
const space = await response.json();Python:
import requests
response = requests.get(
'https://<direct.gateway>/space/1abcdefghijklmno',
headers={'X-API-KEY': 'YOUR_API_KEY'}
)
space = response.json()Response Example
{
"id": "1abcdefghijklmno",
"state": "live",
"title": "Tech Talk: The Future of AI",
"created_at": "2024-10-01T12:00:00.000Z",
"started_at": "2024-10-01T12:05:00.000Z",
"scheduled_start": "2024-10-01T12:00:00.000Z",
"ended_at": null,
"updated_at": "2024-10-01T12:30:00.000Z",
"host_ids": ["987654321"],
"speaker_ids": ["111222333", "444555666"],
"participant_count": 523,
"total_replay_watched": 0,
"is_ticketed": false,
"creator": {
"id": "987654321",
"username": "tech_host",
"name": "Tech Host",
"profile_image_url": "https://pbs.twimg.com/profile_images/...",
"verified": true
},
"topics": [
{
"id": "848920371311001600",
"name": "Technology",
"description": "All things tech"
}
]
}Response Fields
| Field | Type | Description |
|---|---|---|
id | string | Unique Space ID |
state | string | Current state (scheduled, live, ended, cancelled) |
title | string | Space title |
participant_count | integer | Current number of participants |
host_ids | array | User IDs of hosts |
speaker_ids | array | User IDs of speakers |
creator | object | Space creator information |
topics | array | Associated topics/categories |
is_ticketed | boolean | Whether Space requires payment |
started_at | string|null | When Space started (ISO 8601) |
ended_at | string|null | When Space ended (ISO 8601) |
Common Use Cases
- Space Details: Display Space information in your app
- Live Monitoring: Check if Space is currently live
- Participant Tracking: Monitor participant counts
- Content Discovery: Find Spaces by topic or host
Search Spaces
Searches for Spaces based on keywords, state, and other criteria. Useful for discovering relevant Spaces.
Endpoint: GET /spaces/search
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
q | string | Yes | Search term (searches title, description, host names) |
state | string | No | Filter by state: live, scheduled, ended (Default: live) |
limit | integer | No | Number of results (Default: 20, Max: 100) |
Request Examples
# Search for live Spaces
curl --request GET \
--url 'https://<direct.gateway>/spaces/search?q=technology&state=live&limit=20' \
--header 'X-API-KEY: YOUR_API_KEY'
# Search for scheduled Spaces
curl --request GET \
--url 'https://<direct.gateway>/spaces/search?q=AI&state=scheduled' \
--header 'X-API-KEY: YOUR_API_KEY'JavaScript:
// Search live Spaces
const liveSpaces = await fetch(
'https://<direct.gateway>/spaces/search?q=technology&state=live',
{ headers: { 'X-API-KEY': 'YOUR_API_KEY' } }
);
// Search scheduled Spaces
const scheduledSpaces = await fetch(
'https://<direct.gateway>/spaces/search?q=AI&state=scheduled',
{ headers: { 'X-API-KEY': 'YOUR_API_KEY' } }
);Response Example
{
"data": [
{
"id": "1abcdefghijklmno",
"state": "live",
"title": "Tech Talk: The Future of AI",
"participant_count": 523,
"creator": {
"username": "tech_host",
"name": "Tech Host",
"verified": true
},
"started_at": "2024-10-01T12:05:00.000Z"
}
],
"meta": {
"result_count": 15
}
}Search Tips
- Use specific keywords: More specific terms yield better results
- Filter by state: Use
stateparameter to find live vs scheduled Spaces - Combine with topics: Search for Spaces in specific categories
Get Space Participants
Retrieves the complete list of participants in a Space, including hosts, speakers, and listeners with their roles.
Endpoint: GET /space/{space_id}/participants
Path Parameters
| Name | Type | Required | Description |
|---|---|---|---|
space_id | string | Yes | The Space ID |
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
limit | integer | No | Number of results (Default: 100, Max: 1000) |
role | string | No | Filter by role: host, speaker, listener |
Request Examples
# All participants
curl --request GET \
--url 'https://<direct.gateway>/space/1abcdefghijklmno/participants?limit=100' \
--header 'X-API-KEY: YOUR_API_KEY'
# Only hosts
curl --request GET \
--url 'https://<direct.gateway>/space/1abcdefghijklmno/participants?role=host' \
--header 'X-API-KEY: YOUR_API_KEY'JavaScript:
// Get all participants
const participants = await fetch(
'https://<direct.gateway>/space/1abcdefghijklmno/participants',
{ headers: { 'X-API-KEY': 'YOUR_API_KEY' } }
);
// Get only speakers
const speakers = await fetch(
'https://<direct.gateway>/space/1abcdefghijklmno/participants?role=speaker',
{ headers: { 'X-API-KEY': 'YOUR_API_KEY' } }
);Response Example
{
"hosts": [
{
"id": "987654321",
"username": "tech_host",
"name": "Tech Host",
"profile_image_url": "https://pbs.twimg.com/profile_images/...",
"verified": true
}
],
"speakers": [
{
"id": "111222333",
"username": "guest_speaker",
"name": "Guest Speaker",
"invited_at": "2024-10-01T12:00:00.000Z"
}
],
"listeners": [
{
"id": "444555666",
"username": "listener_1",
"joined_at": "2024-10-01T12:10:00.000Z"
}
],
"meta": {
"total_participants": 523,
"host_count": 1,
"speaker_count": 3,
"listener_count": 519
}
}Participant Roles
- Hosts: Space creators and co-hosts, can manage the Space
- Speakers: Users who can speak in the Space
- Listeners: Users who are listening but not speaking
Get User Spaces
Retrieves all Spaces for a specific user, including Spaces they hosted, spoke in, or participated in.
Endpoint: GET /user/{user_id}/spaces
Path Parameters
| Name | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | The user ID |
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
state | string | No | Filter by state: live, scheduled, ended |
role | string | No | Filter by role: host, speaker, participant |
limit | integer | No | Number of results (Default: 20, Max: 100) |
Request Examples
# All Spaces for user
curl --request GET \
--url 'https://<direct.gateway>/user/987654321/spaces?limit=20' \
--header 'X-API-KEY: YOUR_API_KEY'
# Only live Spaces where user is host
curl --request GET \
--url 'https://<direct.gateway>/user/987654321/spaces?state=live&role=host' \
--header 'X-API-KEY: YOUR_API_KEY'Response Example
{
"data": [
{
"id": "1abcdefghijklmno",
"state": "live",
"title": "My Space",
"participant_count": 523,
"user_role": "host",
"started_at": "2024-10-01T12:05:00.000Z"
}
],
"meta": {
"result_count": 5
}
}Get Space Tweets
Retrieves tweets that mention or share a specific Space. Useful for finding discussions about a Space.
Endpoint: GET /space/{space_id}/tweets
Path Parameters
| Name | Type | Required | Description |
|---|---|---|---|
space_id | string | Yes | The Space ID |
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
limit | integer | No | Number of results (Default: 20, Max: 100) |
Request Example
curl --request GET \
--url 'https://<direct.gateway>/space/1abcdefghijklmno/tweets?limit=20' \
--header 'X-API-KEY: YOUR_API_KEY'Response Example
{
"data": [
{
"id": "1234567890123456789",
"text": "Join me in this amazing space! 🎙️",
"author": {
"username": "space_promoter",
"verified": false
},
"created_at": "2024-10-01T12:00:00.000Z",
"space_share": {
"space_id": "1abcdefghijklmno",
"title": "Tech Talk: The Future of AI"
}
}
]
}Get Scheduled Spaces
Retrieves all scheduled (upcoming) Spaces, optionally filtered by date range and topic.
Endpoint: GET /spaces/scheduled
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
from | string | No | Start date (ISO 8601) |
to | string | No | End date (ISO 8601) |
topic | string | No | Topic/Category filter |
limit | integer | No | Number of results (Default: 20, Max: 100) |
Request Examples
# All scheduled Spaces
curl --request GET \
--url 'https://<direct.gateway>/spaces/scheduled?limit=20' \
--header 'X-API-KEY: YOUR_API_KEY'
# Scheduled Spaces in date range
curl --request GET \
--url 'https://<direct.gateway>/spaces/scheduled?from=2024-10-01&to=2024-10-07' \
--header 'X-API-KEY: YOUR_API_KEY'Response Example
{
"data": [
{
"id": "1abcdefghijklmno",
"state": "scheduled",
"title": "Weekly Tech Roundup",
"scheduled_start": "2024-10-02T15:00:00.000Z",
"creator": {
"username": "tech_host",
"name": "Tech Host",
"verified": true
},
"topics": ["Technology"],
"is_ticketed": false,
"reminder_count": 156
}
],
"meta": {
"result_count": 12
}
}Get Live Spaces
Retrieves all currently live Spaces, with optional filters for topic and participant count.
Endpoint: GET /spaces/live
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
topic | string | No | Filter by topic |
min_participants | integer | No | Minimum participant count |
verified_hosts_only | boolean | No | Only Spaces with verified hosts |
limit | integer | No | Number of results (Default: 20, Max: 100) |
Request Examples
# All live Spaces
curl --request GET \
--url 'https://<direct.gateway>/spaces/live?limit=20' \
--header 'X-API-KEY: YOUR_API_KEY'
# Popular live Spaces (100+ participants)
curl --request GET \
--url 'https://<direct.gateway>/spaces/live?min_participants=100' \
--header 'X-API-KEY: YOUR_API_KEY'Response Example
{
"data": [
{
"id": "1abcdefghijklmno",
"state": "live",
"title": "Breaking News Discussion",
"participant_count": 1523,
"creator": {
"username": "news_host",
"verified": true
},
"started_at": "2024-10-01T11:00:00.000Z",
"duration_minutes": 95
}
],
"meta": {
"result_count": 45,
"total_live_spaces": 523
}
}Get Space Recording
Retrieves recording information for an ended Space, including playback URLs and download links.
Endpoint: GET /space/{space_id}/recording
Path Parameters
| Name | Type | Required | Description |
|---|---|---|---|
space_id | string | Yes | The Space ID |
Request Example
curl --request GET \
--url 'https://<direct.gateway>/space/1abcdefghijklmno/recording' \
--header 'X-API-KEY: YOUR_API_KEY'Response Example
{
"space_id": "1abcdefghijklmno",
"state": "ended",
"recording_available": true,
"recording": {
"media_key": "13_1234567890123456789",
"duration_ms": 5400000,
"playback_url": "https://...",
"download_url": "https://...",
"file_size_mb": 125.4
},
"total_replay_watched": 2340,
"ended_at": "2024-10-01T13:30:00.000Z"
}Notes
- Not all Spaces have recordings (host must enable recording)
- Recordings may take time to process after Space ends
recording_availableindicates if recording exists
Space Topics/Categories
Spaces can be categorized by topics. Common topic IDs:
| Topic | ID |
|---|---|
| Technology | 848920371311001600 |
| Gaming | 849075377108226048 |
| Music | 849075383444766721 |
| Sports | 849075379953328129 |
| News | 849075415688937472 |
| Business | 849075381344018432 |
| Entertainment | 849075385153028096 |
Using Topics
// Search Spaces by topic
const techSpaces = await fetch(
'/spaces/search?q=technology&topic=848920371311001600',
{ headers: { 'X-API-KEY': API_KEY } }
);Best Practices
Spaces-Specific Tips
- Monitor live Spaces: Poll live Spaces every 30 seconds to track participant counts
- Cache Space data: Spaces don't change frequently, cache for 2-5 minutes
- Handle state changes: Space states update in near real-time (5-30 second delays are normal)
- Check recording availability: Always check
recording_availablebefore requesting recordings
For general API best practices including error handling, rate limits, and performance optimization, see our Best Practices Guide.
3. Handle State Changes
Monitor state transitions for Spaces:
let previousState = null;
async function checkSpaceState(spaceId) {
const space = await getCachedSpace(spaceId);
if (previousState && previousState !== space.state) {
console.log(`Space state changed: ${previousState} → ${space.state}`);
if (space.state === 'live' && previousState === 'scheduled') {
notifySpaceStarted(space);
} else if (space.state === 'ended' && previousState === 'live') {
notifySpaceEnded(space);
}
}
previousState = space.state;
}4. Filter by Relevance
Use search filters to find relevant Spaces:
async function findRelevantSpaces(keywords, minParticipants = 10) {
const response = await fetch(
`/spaces/live?min_participants=${minParticipants}`,
{ headers: { 'X-API-KEY': API_KEY } }
);
const data = await response.json();
// Filter by keywords
return data.data.filter(space =>
keywords.some(keyword =>
space.title.toLowerCase().includes(keyword.toLowerCase())
)
);
}For comprehensive error handling and rate limits information, see our guides:
- Error Handling Guide - Complete error handling reference
- Rate Limits Guide - Rate limit details and management
Troubleshooting
| Issue | Symptoms | Possible Causes | Solutions |
|---|---|---|---|
| Space state not updating | Space state remains the same despite actual changes | Caching too aggressively, not polling frequently enough, API delay in state updates | Reduce cache TTL for live Spaces, poll more frequently for live Spaces, allow for slight delays (5-30 seconds) in state updates |
| Participant count inaccurate | Participant count doesn't match actual count | Real-time updates have delays, participants joining/leaving rapidly | This is normal - counts update in near real-time (every 10-30 seconds). Poll more frequently for accurate counts, use counts as approximate values |
FAQ
How often do Space states update?
Space states update in near real-time, but there may be slight delays (5-30 seconds) for state changes.
Can I get real-time participant counts?
Yes, but counts update every 10-30 seconds. For real-time accuracy, poll frequently.
Are all Spaces recorded?
No, only Spaces where the host enabled recording. Check recording_available field.
How long are recordings available?
Recordings are typically available for 30 days after the Space ends, but this may vary.
Can I search for Spaces by host?
Yes, use the search endpoint with the host's username or search their Spaces via /user/{user_id}/spaces.
What's the difference between scheduled and live Spaces?
- Scheduled: Has a future start time, not yet active
- Live: Currently running, has active participants
Related Documentation
- Users Endpoints - Get user information
- Tweets Endpoints - Get Space-related tweets
- Error Handling Guide - Error handling
- Rate Limits Guide - Rate limits
- Best Practices - API best practices
