X API v2 Sample Code is a collection of working code examples for the X API v2 across multiple programming languages.
The repository addresses the need for developers to understand how to interact with X API v2 endpoints by providing ready-to-run sample code. It covers the full range of API functionality including posts, users, timelines, streams, lists, spaces, bookmarks, direct messages, media upload, compliance, and usage tracking. Examples are organized by category and authentication type, with support for Bearer Token authentication for read-only operations, OAuth 2.0 PKCE for user actions like posting and liking, and OAuth 1.0a for legacy endpoints.
Developers should choose this repository if they are building applications that integrate with the X platform and need concrete examples before writing their own code. The samples span Python, JavaScript, Ruby, Java, and R, making it suitable for teams using different technology stacks. Coverage varies by language and feature; Python has the most comprehensive examples including direct messages and media upload, while other languages focus on core functionality like posts, users, spaces, and compliance operations. The repository includes an llms.txt context file and api-index.json for machine-readable endpoint information, supporting both human developers and AI-assisted development workflows.
The project maintains active coverage across multiple programming languages with consistent example implementations. Documentation is structured around practical authentication setup and quick-start guidance rather than API reference material. The repository includes supplementary resources designed for integration with language models and automated tooling alongside traditional developer documentation.