X API Skill
Use this skill to run X API v2 operations through uxc + OpenAPI.
Reuse the uxc skill for shared execution, auth, and error-handling guidance.
Prerequisites
uxcis installed and available inPATH.- Network access to
https://api.x.com. - Access to the official OpenAPI schema URL:
https://api.x.com/2/openapi.json
- An X developer app with OAuth2 enabled.
Authentication
Preferred Path: OAuth2 Authorization Code + PKCE (User Context)
This path is required for user-context operations such as bookmarks, home timeline, posting, replying, and DM actions.
- Start OAuth2 login:
uxc auth oauth start x-api-user \
--endpoint https://api.x.com/2 \
--client-id M3VseG9xOXZXZVREZnNqWk9jN1I6MTpjaQ \
--redirect-uri http://127.0.0.1:11111/callback \
--scope users.read \
--scope tweet.read \
--scope tweet.write \
--scope tweet.moderate.write \
--scope media.write \
--scope like.read \
--scope like.write \
--scope follows.read \
--scope follows.write \
--scope list.read \
--scope list.write \
--scope timeline.read \
--scope space.read \
--scope mute.read \
--scope mute.write \
--scope block.read \
--scope block.write \
--scope bookmark.read \
--scope bookmark.write \
--scope dm.read \
--scope dm.write \
--authorization-endpoint https://x.com/i/oauth2/authorize \
--token-endpoint https://api.x.com/2/oauth2/token
This default example intentionally includes the full OAuth2 user scope set exposed by the current X OpenAPI surface, excluding offline.access to avoid refresh-token compatibility failures observed on some X app configurations. Add --scope offline.access only when you explicitly need long-lived refresh behavior and have verified token refresh works for your app.
- Open the returned authorization URL in browser and finish consent.
- Complete login with the callback URL:
uxc auth oauth complete x-api-user \
--session-id <session_id> \
--authorization-response '<callback_url>'
- Bind credential to X API:
uxc auth binding add \
--id x-api-user \
--host api.x.com \
--path-prefix /2 \
--scheme https \
--credential x-api-user \
--priority 100
- Verify binding:
uxc auth binding match https://api.x.com/2
Optional Path: App-only Bearer Token (Public Reads)
App-only bearer auth is useful for selected public read endpoints.
Do not embed bearer tokens in this skill or repository. Configure local credentials only.
uxc auth credential set x-api-app \
--auth-type bearer \
--secret-env X_API_BEARER_TOKEN
uxc auth binding add \
--id x-api-app \
--host api.x.com \
--path-prefix /2 \
--scheme https \
--credential x-api-app \
--priority 90
Use --auth x-api-app when you intentionally want app-only requests.
Core Workflow
-
Use fixed link command by default:
command -v x-openapi-cli- If missing, create it:
uxc link x-openapi-cli https://api.x.com --schema-url https://api.x.com/2/openapi.json x-openapi-cli -h
-
Inspect operation schema first:
x-openapi-cli get:/2/users/me -hx-openapi-cli get:/2/users/{id}/bookmarks -hx-openapi-cli post:/2/tweets -h
-
Execute reads before writes:
x-openapi-cli get:/2/users/mex-openapi-cli get:/2/users/{id}/bookmarks id=<user_id> max_results=20x-openapi-cli get:/2/users/{id}/timelines/reverse_chronological id=<user_id> max_results=20
-
Execute writes with explicit user confirmation:
- key/value:
x-openapi-cli post:/2/tweets text='hello from uxc' - positional JSON:
x-openapi-cli post:/2/tweets '{"text":"hello from uxc"}'
- key/value:
Subscribe / Stream Status
X stream endpoints are HTTP streaming routes and can be used with uxc subscribe raw HTTP stream mode.
Example:
uxc subscribe start https://api.x.com/2/tweets/search/stream \
--auth x-api-app \
--sink file:$HOME/.uxc/subscriptions/x-search-stream.ndjson
Use the relevant stream rule-management endpoints before starting stream consumers.
Guardrails
- Keep automation on JSON output envelope; do not use
--text. - Parse stable fields first:
ok,kind,protocol,data,error. x-openapi-cli <operation> ...is equivalent touxc https://api.x.com --schema-url https://api.x.com/2/openapi.json <operation> ....- OAuth2 PKCE is the default path for user-context operations.
- Do not commit or hardcode bearer tokens, client secrets, or refresh tokens.
- Treat
post:/2/tweets, DM endpoints, bookmark write endpoints, and stream rule mutation endpoints as write/high-risk operations; require explicit user confirmation before execution.
References
- Usage patterns:
references/usage-patterns.md - X API OpenAPI schema:
https://api.x.com/2/openapi.json - X OAuth2 authorization code with PKCE:
https://docs.x.com/fundamentals/authentication/oauth-2-0/authorization-code - X OAuth2 app-only bearer auth:
https://docs.x.com/fundamentals/authentication/oauth-2-0/application-only