Send Message
POST
/tw-v2/xchat/sendThis endpoint costs 10 API units per call. · How billing works
Description
Send an end-to-end encrypted direct message via X Chat.
Prerequisite: You must call
/xchat/setupfirst before sending messages.
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
| auth | string | required | Account authentication token (auth_token cookie value) |
| recipient | string | required | Twitter user ID of the message recipient (numeric string) |
| messagestringrequired | string | required | The message text to send (max 10,000 characters) |
| conversation | string | optional | Optional conversation token returned by a previous XChat request |
| conversation | string | optional | Optional version identifier for the supplied encrypted conversation key |
| encrypted | string | optional | Optional encrypted conversation key returned by XChat setup or history |
| proxystringoptional | string | optional | Proxy in format 'hostname:port@username:password' |
Code Examples
const body = {
authToken: 'YOUR_AUTH_TOKEN',
recipientId: '9876543210987654321',
message: 'Hello! This is an encrypted message.'
};
const response = await fetch('https://api.tweetapi.com/tw-v2/xchat/send', {
method: 'POST',
headers: {
'X-API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
});
const data = await response.json();
console.log(data);
Response
Success Response (200 OK)
200
{
"messageId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"conversationId": "5003555930970613276:9876543210987654321",
"timestamp": 1768479256916,
"status": "sent",
"recipientId": "9876543210987654321",
"mode": "e2e",
"retried": true
}
retriedis optional and only appears when the API had to invalidate stale cache data and retry send automatically.
Error Responses
400s Errors
400X Chat not initialized. Call /xchat/setup first.
400Could not send message. Try initiating a conversation from the official app first.
400The encryptedConversationKey you sent doesn't match your X Chat keys. Check it, or leave it out to use the conversation's current key.
409Your stored X Chat keys no longer match this conversation, for example after a PIN change. Call /xchat/setup again to refresh them.
404Recipient does not have X Chat enabled.
401Invalid or expired authentication token.
429Rate limit or quota exceeded.