Code Examples. Copy, Paste, Ship.
Every example on this page is a working integration pattern for the Perception X2 API. Four languages, twenty use cases, zero boilerplate.
4 Languages · 20 Use Cases · Production Tested · Copy-Paste Ready
Every Example Self-Contained and Error-Handled
Each example is a working integration pattern for the Perception X2 API — self-contained, error-handled, and following SDK best practices. Use them as starting points for your integrations or as reference for API behavior.
Code examples cover every major Perception X2 operation across Python, JavaScript/TypeScript, Go, and cURL. Each snippet is self-contained — copy, paste, and adapt for your integration. Examples include error handling, retry logic, and production-ready patterns — not just the happy path.
Sentiment analysis. Narrative deployment. Crisis detection. Webhook verification. Real-time streaming. Batch exports. Every example demonstrates a specific capability with working code that ships to production.
Examples are versioned alongside the SDK. The same example works across SDK minor versions. When API features evolve, examples are updated to reflect the latest patterns. Developers working with a specific SDK version see examples that match exactly.
Why Most API Code Examples Fail in Production
Most API examples show the happy path. Production code needs error handling, retry logic, pagination, and rate limit awareness. Perception X2 examples include all of these from the start.
Missing Error Handling
Examples that ignore error paths leave developers guessing how to handle 429 rate limits, 401 auth failures, and 500 server errors. Production code needs explicit handling for every failure mode.
No Retry Logic
Without retry patterns, transient failures cause integration outages. Exponential backoff with jitter is the standard — but most examples omit it entirely.
Hardcoded Values
Examples that hardcode credentials, IDs, and URLs train bad habits. Production code uses environment variables, secret managers, and configuration systems.
Ignoring Pagination
Examples that return a single page of results fail at scale. Production integrations need cursor-based pagination with iteration patterns for large datasets.
Language Mismatch
Examples in one language force teams to translate patterns manually. Multi-language examples ensure every team works in their preferred language without translation work.
Version Drift
Examples that lag SDK versions break integrations. Versioned examples ensure code that ships today still works after SDK minor updates.
No Test Coverage
Examples without tests cannot be validated. Production-ready code includes test patterns and sandbox environments for validation before deployment.
Missing Documentation
Examples without context leave developers guessing. Each Perception X2 example includes the use case, expected response, and integration context.
Every Example Engineered for Production
Every Perception X2 code example is designed for production deployment — error handling, retry logic, pagination, and rate limit awareness included from the start.
Error Handling Built-In
Every example handles common error paths — authentication failures, rate limits, validation errors, and server errors. Type-specific error handling in every language.
Retry with Exponential Backoff
Transient failures trigger automatic retries with exponential backoff and jitter. Configurable retry policies per request or globally across the client.
Environment Configuration
Credentials and configuration come from environment variables, never hardcoded. Production deployments use secret managers, not source code.
Pagination Patterns
Cursor-based pagination with iteration helpers. Manual and auto-pagination patterns for every list endpoint. SDK iterators handle large datasets efficiently.
Twenty Use Cases Across the Platform
Basic Sentiment Query
Query sentiment analytics across platforms with normalized scores and supporting metadata. The simplest entry point to Perception X2.
OAuth 2.0 Authentication
Obtain access tokens for API access using client credentials. SDKs handle this automatically — the raw flow is shown for reference.
Narrative Deployment
Create and launch narratives across platforms with targeting and scheduling. Track deployment status in real time.
Real-Time Sentiment Stream
Subscribe to live sentiment events via WebSocket. Sub-200ms delivery, automatic reconnection, and event replay.
Batch Analytics Export
Export historical analytics data in bulk. CSV, JSON, and Parquet formats. Configurable date ranges and granularity.
What These Examples Cover
Sentiment Analysis
Real-time and historical sentiment queries with normalized scores, confidence levels, and emotional dimension analysis.
Narrative Deployment
Create, deploy, list, and schedule narratives across multiple platforms. Targeting, scheduling, and tracking included.
WebSocket Streaming
Real-time event streaming with channel subscriptions, filters, and automatic reconnection with event replay.
Webhook Integration
Register webhooks, verify HMAC-SHA256 signatures, and handle event processing with idempotent patterns.
Crisis Detection
Monitor and respond to crisis events with severity classification, recommended actions, and automated response workflows.
Audience Targeting
Create audience segments with demographic, behavioral, and psychographic filters. Query segment analytics.
What Developers Build With These Examples
Real-Time Sentiment Dashboard
Build dashboards displaying live sentiment scores. WebSocket streaming for live updates, REST for historical data.
Automated Narrative Deployment
Integrate Perception X2 into content management workflows. Deploy narratives to 50+ platforms through single API calls.
Crisis Response Automation
Configure webhooks for crisis events. Execute predefined playbooks — activate counter-narratives, notify stakeholders.
Competitive Intelligence Platform
Aggregate competitive data across platforms. Schedule batch queries, store in analytics infrastructure, generate reports.
Mobile Application Integration
Add sentiment analysis to mobile applications. Lightweight SDK initialization, background fetching, push notifications.
Why These Code Examples
Zero Boilerplate
Every example is self-contained. Copy, paste, run. No setup scripts, no missing imports, no partial code.
Production Patterns
Error handling, retry logic, pagination — all included. Patterns that ship to production, not tutorial snippets.
Multi-Language
Python, JavaScript/TypeScript, Go, and cURL. Same example, four languages. No translation work required.
Versioned With SDKs
Examples match SDK minor versions. Code that ships today still works after SDK updates.
Expected Responses
Every example shows expected response format. Compare your output against documented responses to verify integration.
Error Path Coverage
Error handling patterns included for every example. Authentication failures, rate limits, validation errors covered.
What Makes These Code Examples Different
Most code examples show the happy path. Perception X2 examples show production patterns. Every snippet is self-contained, error-handled, and tested.
Self-Contained Snippets
Every example is complete. Copy, paste, run. No setup scripts, no missing imports, no partial code.
Production Patterns
Error handling, retry logic, pagination — all included. Patterns that ship to production, not tutorial snippets.
Four Languages, One Pattern
Python, JavaScript/TypeScript, Go, and cURL. Same example, four languages. No translation work.
Expected Responses
Every example shows expected response format. Compare your output against documented responses.
Error Path Coverage
Error handling patterns included. Authentication failures, rate limits, validation errors — all covered.
Versioned With SDKs
Examples match SDK versions. Code that ships today still works after SDK updates.
Built for Developers at Every Skill Level
Python Developers
Rapid prototyping, data-intensive integrations, async/await patterns. Pydantic models and type hints included.
JavaScript Developers
Web applications, real-time dashboards, Node.js backend services. Full TypeScript definitions.
Go Developers
High-throughput backend services, microservices, performance-critical integrations. Context-aware patterns.
DevOps Engineers
CI/CD integration, monitoring scripts, automation workflows. cURL examples for shell scripting.
Data Engineers
Batch processing pipelines, analytics exports, ETL workflows. Large dataset handling patterns.
Full-Stack Developers
End-to-end integration patterns. Frontend dashboards powered by backend APIs with WebSocket streams.
The Platform Behind the Examples
15+ Years of Operational Excellence
Every example refined through thousands of real-world deployments across the world's most demanding environments.
300+ Elite Client Integrations
Trusted by governments, global enterprises, and institutions across multiple continents.
Zero Security Incidents
Your most sensitive API data protected by military-grade security. Zero incidents in 15+ years.
99.9999% Uptime SLA
Tier-based rate limits, automatic retry, and circuit breaker patterns. Operational concerns covered.
Multi-Language SDK Coverage
Python, JavaScript/TypeScript, Go, and more. Same API surface across all official SDKs.
Production-Ready Patterns
Every example demonstrates production patterns. Code that ships, not code that demos.
Code Examples — Common Developer Questions
Which programming languages are supported in the code examples?
Are the code examples production-ready?
How do I run the code examples?
Do the examples include the expected response format?
How are the examples versioned?
Can I use these examples in commercial products?
What if an example does not work in my environment?
How do I contribute examples to Perception X2?
Code Examples — What Developers Ask
What is the fastest way to test Perception X2?
Do the examples work in the sandbox environment?
Can I use these examples with raw HTTP instead of the SDK?
How do the examples handle rate limiting?
What happens if my credentials expire during an example run?
Begin Building with Perception X2
Copy any example, install the SDK, and execute your first API call within minutes. The Developer Portal provides sandbox credentials and the full example catalog.
Sandbox environment available for testing all examples without affecting production deployments.
Multi-language coverage — every example in Python, JavaScript, Go, and cURL.