Twitter/X Chat API
The Chat API from Twitter/X — 16 operation(s) for chat.
The Chat API from Twitter/X — 16 operation(s) for chat.
openapi: 3.0.0
info:
description: X API v2 available endpoints
version: '2.166'
title: X API v2 Account Activity Chat API
termsOfService: https://developer.x.com/en/developer-terms/agreement-and-policy.html
contact:
name: X Developers
url: https://developer.x.com/
license:
name: X Developer Agreement and Policy
url: https://developer.x.com/en/developer-terms/agreement-and-policy.html
servers:
- description: X API
url: https://api.x.com
tags:
- name: Chat
paths:
/2/chat/conversations:
get:
security:
- OAuth2UserToken:
- dm.read
- users.read
- UserToken: []
tags:
- Chat
summary: Get Chat Conversations
description: Retrieves a list of Chat conversations for the authenticated user's inbox.
externalDocs:
url: https://developer.x.com/
operationId: getChatConversations
parameters:
- name: max_results
in: query
description: Maximum number of conversations to return.
required: false
schema:
type: integer
minimum: 1
maximum: 100
format: int32
default: 10
style: form
- name: pagination_token
in: query
description: Token for pagination to retrieve the next page of results.
required: false
schema:
type: string
style: form
- $ref: '#/components/parameters/ChatConversationFieldsParameter'
- $ref: '#/components/parameters/ChatConversationExpansionsParameter'
- $ref: '#/components/parameters/UserFieldsParameter'
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatGetConversationsResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/conversations/group:
post:
security:
- OAuth2UserToken:
- dm.write
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Create Chat Group Conversation
description: Creates a new encrypted Chat group conversation on behalf of the authenticated user.
externalDocs:
url: https://developer.x.com/
operationId: createChatConversation
parameters: []
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChatCreateConversationRequest'
required: true
responses:
'201':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatCreateConversationResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/conversations/group/initialize:
post:
security:
- OAuth2UserToken:
- dm.write
- UserToken: []
tags:
- Chat
summary: Initialize Chat Group
description: "Initializes a new XChat group conversation and returns a unique conversation ID.\n\nThis endpoint is the first step in creating a group chat. The returned conversation_id \nshould be used in subsequent calls to POST /chat/conversations/group to fully create and \nconfigure the group with members, admins, encryption keys, and other settings.\n\n**Workflow:**\n1. Call this endpoint to get a `conversation_id`\n2. Use that `conversation_id` when calling `POST /chat/conversations/group` to create the group\n\n**Authentication:**\n- Requires OAuth 1.0a User Context or OAuth 2.0 User Context\n- Required scope: `dm.write`\n"
externalDocs:
url: https://developer.x.com/
operationId: initializeChatGroup
parameters: []
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatInitializeGroupResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/conversations/{id}:
get:
security:
- OAuth2UserToken:
- dm.read
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Get Chat Conversation
description: Returns metadata for a Chat conversation including type, muted status, and group details. Use chat_conversation.fields to select which fields are returned. Use expansions to hydrate member, admin, or participant user objects. Use user.fields to control which profile fields are returned for expanded users.
externalDocs:
url: https://developer.x.com/
operationId: getChatConversation
parameters:
- name: id
in: path
description: The conversation ID. For 1:1 conversations, use the recipient user ID or dash-separated canonical ID. For group conversations, use the group ID (prefixed with 'g').
required: true
schema:
type: string
style: simple
- $ref: '#/components/parameters/ChatConversationFieldsParameter'
- $ref: '#/components/parameters/ChatConversationExpansionsParameter'
- $ref: '#/components/parameters/UserFieldsParameter'
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatGetConversationsResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/conversations/{id}/events:
get:
security:
- OAuth2UserToken:
- dm.read
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Get Chat Conversation Events
description: Retrieves messages and key change events for a specific Chat conversation with pagination support. For 1:1 conversations, provide the recipient's user ID; the server constructs the canonical conversation ID from the authenticated user and recipient.
externalDocs:
url: https://developer.x.com/
operationId: getChatConversationEvents
parameters:
- name: id
in: path
description: The recipient's user ID for a 1:1 conversation, the hyphen-separated 1:1 conversation ID (e.g. '123-456'), or a group conversation ID (prefixed with 'g').
required: true
schema:
$ref: '#/components/schemas/ChatConversationOrRecipientId'
style: simple
- name: max_results
in: query
description: Maximum number of message events to return.
required: false
schema:
type: integer
minimum: 1
maximum: 100
format: int32
default: 10
style: form
- name: pagination_token
in: query
description: Token for pagination to retrieve the next page of results.
required: false
schema:
type: string
style: form
- $ref: '#/components/parameters/ChatMessageEventFieldsParameter'
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatGetConversationResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/conversations/{id}/keys:
post:
security:
- OAuth2UserToken:
- dm.write
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Add Conversation Keys
description: 'Adds (initializes or rotates) the encryption keys for a Chat conversation.
Call this before sending messages in a new 1:1 conversation, and again with a
newer key version to rotate the conversation key.
For 1:1 conversations, provide the recipient''s user ID as the conversation_id.
The server constructs the canonical conversation ID from the authenticated user
and recipient.
The request body must contain the conversation key version and participant keys
(the conversation key encrypted for each participant using their public key).
**Workflow (new 1:1 conversation):**
1. Generate a conversation key using the SDK
2. Encrypt the key for both participants using their public keys
3. Call this endpoint to register the keys
4. Send messages using `POST /chat/conversations/{id}/messages`
To rotate the keys of an existing conversation, repeat the same call with a
newer conversation key version.
**Authentication:**
- Requires OAuth 1.0a User Context or OAuth 2.0 User Context
- Required scopes: `tweet.read`, `users.read`, `dm.write`
'
externalDocs:
url: https://developer.x.com/
operationId: addConversationKeys
parameters:
- name: id
in: path
description: The recipient's user ID for a 1:1 conversation, the hyphen-separated 1:1 conversation ID (e.g. '123-456'), or a group conversation ID (prefixed with 'g').
required: true
schema:
$ref: '#/components/schemas/ChatConversationOrRecipientId'
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChatInitializeConversationKeysRequest'
required: true
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatInitializeConversationKeysResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/conversations/{id}/members:
post:
security:
- OAuth2UserToken:
- dm.write
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Add members to a Chat group conversation
description: Adds one or more members to an existing encrypted Chat group conversation, rotating the conversation key.
externalDocs:
url: https://developer.x.com/
operationId: addChatGroupMembers
parameters:
- name: id
in: path
description: The Chat group conversation ID (prefixed with 'g').
required: true
schema:
$ref: '#/components/schemas/ChatConversationOrRecipientId'
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChatAddGroupMembersRequest'
required: true
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatAddGroupMembersResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/conversations/{id}/messages:
post:
security:
- OAuth2UserToken:
- dm.write
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Send Chat Message
description: Sends an encrypted message to a specific Chat conversation. For 1:1 conversations, provide the recipient's user ID; the server constructs the canonical conversation ID from the authenticated user and recipient.
externalDocs:
url: https://developer.x.com/
operationId: sendChatMessage
parameters:
- name: id
in: path
description: The recipient's user ID for a 1:1 conversation, the hyphen-separated 1:1 conversation ID (e.g. '123-456'), or a group conversation ID (prefixed with 'g').
required: true
schema:
$ref: '#/components/schemas/ChatConversationOrRecipientId'
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChatSendMessageRequest'
required: true
responses:
'201':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatSendMessageResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/conversations/{id}/read:
post:
security:
- OAuth2UserToken:
- dm.write
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Mark Conversation as Read
description: Marks a specific Chat conversation as read on behalf of the authenticated user. For 1:1 conversations, provide the recipient's user ID; the server constructs the canonical conversation ID from the authenticated user and recipient.
externalDocs:
url: https://developer.x.com/
operationId: markChatConversationRead
parameters:
- name: id
in: path
description: The recipient's user ID for a 1:1 conversation, the hyphen-separated 1:1 conversation ID (e.g. '123-456'), or a group conversation ID (prefixed with 'g').
required: true
schema:
$ref: '#/components/schemas/ChatConversationOrRecipientId'
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChatMarkConversationReadRequest'
required: true
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatMarkConversationReadResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/conversations/{id}/typing:
post:
security:
- OAuth2UserToken:
- dm.write
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Send Typing Indicator
description: Sends a typing indicator to a specific Chat conversation on behalf of the authenticated user. For 1:1 conversations, provide the recipient's user ID; the server constructs the canonical conversation ID from the authenticated user and recipient.
externalDocs:
url: https://developer.x.com/
operationId: sendChatTypingIndicator
parameters:
- name: id
in: path
description: The recipient's user ID for a 1:1 conversation, the hyphen-separated 1:1 conversation ID (e.g. '123-456'), or a group conversation ID (prefixed with 'g').
required: true
schema:
$ref: '#/components/schemas/ChatConversationOrRecipientId'
style: simple
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatSendTypingIndicatorResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/media/upload/initialize:
post:
security:
- OAuth2UserToken:
- media.write
- UserToken: []
tags:
- Chat
summary: Initialize Chat Media Upload
description: Initializes an XChat media upload session.
externalDocs:
url: https://docs.x.com/x-api/media/media-upload
operationId: chatMediaUploadInitialize
parameters: []
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChatMediaUploadInitializeRequest'
required: true
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatMediaUploadInitializeResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/media/upload/{id}/append:
post:
security:
- OAuth2UserToken:
- media.write
- UserToken: []
tags:
- Chat
summary: Append Chat Media Upload
description: Appends media data to an XChat upload session.
externalDocs:
url: https://docs.x.com/x-api/media/media-upload
operationId: chatMediaUploadAppend
parameters:
- name: id
in: path
description: The session/resume id from initialize.
required: true
schema:
type: string
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChatMediaUploadAppendRequest'
multipart/form-data:
schema:
$ref: '#/components/schemas/ChatMediaUploadAppendRequest'
required: true
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/MediaUploadAppendResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/media/upload/{id}/finalize:
post:
security:
- OAuth2UserToken:
- media.write
- UserToken: []
tags:
- Chat
summary: Finalize Chat Media Upload
description: Finalizes an XChat media upload session.
externalDocs:
url: https://docs.x.com/x-api/media/media-upload
operationId: chatMediaUploadFinalize
parameters:
- name: id
in: path
description: The session/resume id from initialize.
required: true
schema:
type: string
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChatMediaUploadFinalizeRequest'
required: true
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatMediaUploadFinalizeResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/chat/media/{id}/{media_hash_key}:
get:
security:
- OAuth2UserToken:
- media.write
- UserToken: []
tags:
- Chat
summary: Download Chat Media
description: Downloads encrypted media bytes from an XChat conversation. The response body contains raw binary bytes. For 1:1 conversations, provide the recipient's user ID; the server constructs the canonical conversation ID from the authenticated user and recipient.
externalDocs:
url: https://developer.x.com/
operationId: chatMediaDownload
parameters:
- name: id
in: path
description: The recipient's user ID for a 1:1 conversation, the hyphen-separated 1:1 conversation ID (e.g. '123-456'), or a group conversation ID (prefixed with 'g').
required: true
schema:
$ref: '#/components/schemas/ChatConversationOrRecipientId'
style: simple
- name: media_hash_key
in: path
description: The media hash key returned from the upload initialize step.
required: true
schema:
$ref: '#/components/schemas/MediaHashKey'
style: simple
responses:
'200':
description: The request has succeeded.
content:
application/octet-stream:
schema:
$ref: '#/components/schemas/BinaryPayload'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/users/public_keys:
get:
security:
- OAuth2UserToken:
- dm.read
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Get public keys for multiple users
description: Returns the public keys and Juicebox configuration for the specified users.
externalDocs:
url: https://developer.x.com/
operationId: getUsersPublicKeys
parameters:
- name: ids
in: query
description: A list of User IDs, comma-separated. You can specify up to 100 IDs.
required: true
example: 2244994945,6253282,12
schema:
type: array
minItems: 1
maxItems: 100
items:
$ref: '#/components/schemas/UserId'
explode: false
style: form
- $ref: '#/components/parameters/PublicKeyFieldsParameter'
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/Get2UsersPublicKeysResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/2/users/{id}/public_keys:
get:
security:
- OAuth2UserToken:
- dm.read
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Get user public keys
description: Returns the public keys and Juicebox configuration for the specified user.
externalDocs:
url: https://developer.x.com/
operationId: getUsersPublicKey
parameters:
- name: id
in: path
description: The ID of the User to lookup.
required: true
example: '2244994945'
schema:
$ref: '#/components/schemas/UserId'
style: simple
- $ref: '#/components/parameters/PublicKeyFieldsParameter'
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/Get2UsersIdPublicKeysResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
post:
security:
- OAuth2UserToken:
- dm.write
- tweet.read
- users.read
- UserToken: []
tags:
- Chat
summary: Add public key
description: Registers a user's public key for X Chat encryption.
externalDocs:
url: https://developer.x.com/
operationId: addUserPublicKey
parameters:
- name: id
in: path
description: The ID of the requesting user.
required: true
schema:
$ref: '#/components/schemas/UserId'
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ChatAddPublicKeyRequest'
required: true
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/ChatAddPublicKeyResponse'
default:
description: The request has failed.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
components:
schemas:
HashtagEntity:
allOf:
- $ref: '#/components/schemas/EntityIndicesInclusiveExclusive'
- $ref: '#/components/schemas/HashtagFields'
ChatActionSignature:
type: object
description: Cryptographic signature for a chat action.
required:
- message_id
- encoded_message_event_detail
- message_event_signature
properties:
encoded_message_event_detail:
type: string
description: Base64-encoded message event detail.
minLength: 1
pattern: ^[A-Za-z0-9+/=_-]+$
message_event_signature:
$ref: '#/components/schemas/ChatActionMessageEventSignature'
message_id:
type: string
description: Client-generated ID of the message being signed.
minLength: 1
signature_payload:
type: string
description: Payload string the client signed; used only in server-side failure logs.
User:
type: object
description: The X User object.
required:
- id
- name
- username
properties:
affiliation:
type: object
description: Metadata about a user's affiliation.
properties:
badge_url:
type: string
description: The badge URL corresponding to the affiliation.
format: uri
description:
type: string
description: The description of the affiliation.
url:
type: string
description: The URL, if available, to details about an affiliation.
format: uri
user_id:
type: array
minItems: 1
items:
$ref: '#/components/schemas/UserId'
connection_status:
type: array
description: Returns detailed information about the relationship between two users.
minItems: 0
items:
type: string
description: Type of connection between users.
enum:
- follow_request_received
- follow_request_sent
- blocking
- followed_by
- following
- muting
created_at:
type: string
description: Creation time of this User.
format: date-time
description:
type: string
description: The text of this User's profile description (also known as bio), if the User provided one.
entities:
type: object
description: A list of metadata found in the User's profile description.
properties:
description:
$ref: '#/components/schemas/FullTextEntities'
url:
type: object
description: Expanded details for the URL specified in the User's profile, with start and end indices.
properties:
urls:
type: array
minItems: 1
items:
$ref: '#/components/schemas/UrlEntity'
id:
$ref: '#/components/schemas/UserId'
location:
type: string
description: The location specified in the User's profile, if the User provided one. As this is a freeform value, it may not indicate a valid location, but it may be fuzzily evaluated when performing searches with location queries.
most_recent_tweet_id:
$ref: '#/components/schemas/TweetId'
name:
type: string
description: The friendly name of this User, as shown on their profile.
pinned_tweet_id:
$ref: '#/components/schemas/TweetId'
profile_banner_url:
type: string
description: The URL to the profile banner for this User.
format: uri
profile_image_url:
type: string
description: The URL to the profile image for this User.
format: uri
protected:
type: boolean
description: Indicates if this User has chosen to protect their Posts (in other words, if this User's Posts are private).
public_metrics:
type: object
description: A list of metrics for this User.
required:
- followers_count
- following_count
- tweet_count
- listed_count
properties:
followers_count:
type: integer
description: Number of Users who are following this User.
following_count:
type: integer
description: Number of Users this User is following.
like_count:
type: integer
description: The number of likes created by this User.
listed_count:
type: integer
description: The number of lists that include this User.
tweet_count:
type: integer
description: The number of Posts (including Retweets) posted by this User.
receives_your_dm:
type: boolean
description: Indicates if you can send a DM to this User
subscription_type:
type: string
description: 'The X Blue subscription type of the user, eg: Basic, Premium, PremiumPlus or None.'
enum:
- Basic
- Premium
- PremiumPlus
- None
url:
type: string
description: The URL specified in the User's profile.
username:
$ref: '#/components/schemas/UserName'
verified:
type: boolean
description: Indicate if this User is a verified X User.
verified_type:
type: string
description: 'The X Blue verified type of the user, eg: blue, government, business or none.'
enum:
- blue
- government
- business
- none
withheld:
$ref: '#/co
# --- truncated at 32 KB (94 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/twitter-x/refs/heads/main/openapi/twitter-x-chat-api-openapi.yml