Production-Ready Snippets for Every Operation

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

Python, JavaScript, Go, cURL
Self-Contained Snippets
Error Handling Included
Production Patterns
Production-Ready Code

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.

20+
Use Cases
4
Languages
0
Boilerplate
100%
Production Tested
All
SDK Patterns
The Boilerplate Problem

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.

01

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.

02

No Retry Logic

Without retry patterns, transient failures cause integration outages. Exponential backoff with jitter is the standard — but most examples omit it entirely.

03

Hardcoded Values

Examples that hardcode credentials, IDs, and URLs train bad habits. Production code uses environment variables, secret managers, and configuration systems.

04

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.

05

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.

06

Version Drift

Examples that lag SDK versions break integrations. Versioned examples ensure code that ships today still works after SDK minor updates.

07

No Test Coverage

Examples without tests cannot be validated. Production-ready code includes test patterns and sandbox environments for validation before deployment.

08

Missing Documentation

Examples without context leave developers guessing. Each Perception X2 example includes the use case, expected response, and integration context.

Production-Ready Patterns

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.

Example Categories

Twenty Use Cases Across the Platform

01
Step 01

Basic Sentiment Query

Query sentiment analytics across platforms with normalized scores and supporting metadata. The simplest entry point to Perception X2.

02
Step 02

OAuth 2.0 Authentication

Obtain access tokens for API access using client credentials. SDKs handle this automatically — the raw flow is shown for reference.

03
Step 03

Narrative Deployment

Create and launch narratives across platforms with targeting and scheduling. Track deployment status in real time.

04
Step 04

Real-Time Sentiment Stream

Subscribe to live sentiment events via WebSocket. Sub-200ms delivery, automatic reconnection, and event replay.

05
Step 05

Batch Analytics Export

Export historical analytics data in bulk. CSV, JSON, and Parquet formats. Configurable date ranges and granularity.

Coverage

What These Examples Cover

Feature

Sentiment Analysis

Real-time and historical sentiment queries with normalized scores, confidence levels, and emotional dimension analysis.

Feature

Narrative Deployment

Create, deploy, list, and schedule narratives across multiple platforms. Targeting, scheduling, and tracking included.

Feature

WebSocket Streaming

Real-time event streaming with channel subscriptions, filters, and automatic reconnection with event replay.

Feature

Webhook Integration

Register webhooks, verify HMAC-SHA256 signatures, and handle event processing with idempotent patterns.

Feature

Crisis Detection

Monitor and respond to crisis events with severity classification, recommended actions, and automated response workflows.

Feature

Audience Targeting

Create audience segments with demographic, behavioral, and psychographic filters. Query segment analytics.

Example Categories

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.

Live

Automated Narrative Deployment

Integrate Perception X2 into content management workflows. Deploy narratives to 50+ platforms through single API calls.

50+ Platforms

Crisis Response Automation

Configure webhooks for crisis events. Execute predefined playbooks — activate counter-narratives, notify stakeholders.

Real-Time

Competitive Intelligence Platform

Aggregate competitive data across platforms. Schedule batch queries, store in analytics infrastructure, generate reports.

Scheduled

Mobile Application Integration

Add sentiment analysis to mobile applications. Lightweight SDK initialization, background fetching, push notifications.

Mobile
Benefits

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.

Why Perception X2 Examples

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.

01

Self-Contained Snippets

Every example is complete. Copy, paste, run. No setup scripts, no missing imports, no partial code.

02

Production Patterns

Error handling, retry logic, pagination — all included. Patterns that ship to production, not tutorial snippets.

03

Four Languages, One Pattern

Python, JavaScript/TypeScript, Go, and cURL. Same example, four languages. No translation work.

04

Expected Responses

Every example shows expected response format. Compare your output against documented responses.

05

Error Path Coverage

Error handling patterns included. Authentication failures, rate limits, validation errors — all covered.

06

Versioned With SDKs

Examples match SDK versions. Code that ships today still works after SDK updates.

Who Uses These Examples

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.

Why Perception X2

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.

Frequently Asked Questions

Code Examples — Common Developer Questions

Which programming languages are supported in the code examples?
Perception X2 code examples are provided in Python, JavaScript/TypeScript, Go, and cURL. Each example shows the same operation in all four languages.
Are the code examples production-ready?
Yes. Every example includes error handling, retry logic, and pagination patterns. Examples demonstrate production patterns, not tutorial snippets.
How do I run the code examples?
Install the relevant SDK (pip install perception-sdk, npm install @cryptomize/perception-sdk, or go get github.com/CryptoMize/perception-sdk-go), obtain OAuth 2.0 credentials, and execute the snippet in your development environment.
Do the examples include the expected response format?
Yes. Every example documents the expected response structure, including status codes, response bodies, and error formats.
How are the examples versioned?
Examples are versioned alongside the SDKs. When SDK minor versions are released, examples are updated to reflect the latest patterns. Code that ships today still works after SDK updates.
Can I use these examples in commercial products?
Yes. Perception X2 code examples are provided under a permissive license. Use them as starting points, modify them for your needs, and ship to production.
What if an example does not work in my environment?
Check that you are using the latest SDK version, your credentials are valid, and your environment meets the SDK minimum requirements. The Integration Guides page provides troubleshooting for common issues.
How do I contribute examples to Perception X2?
Code examples are maintained by the Perception X2 engineering team. Submit suggestions through the Developer Portal — community-contributed examples that meet quality standards are added to the official repository.
People Also Ask

Code Examples — What Developers Ask

What is the fastest way to test Perception X2?
Install the SDK, obtain OAuth 2.0 credentials from the Developer Portal, and execute the Basic Sentiment Query example. You will have a working API call within minutes.
Do the examples work in the sandbox environment?
Yes. All examples work in the sandbox environment. Switch the base URL to the sandbox endpoint and use sandbox credentials to test against realistic data without affecting production.
Can I use these examples with raw HTTP instead of the SDK?
Yes. cURL examples demonstrate the raw HTTP flow. Use these as a reference for integrating Perception X2 into languages without official SDK coverage.
How do the examples handle rate limiting?
SDK examples handle rate limiting automatically. Raw HTTP examples include 429 response handling with exponential backoff and Retry-After header support.
What happens if my credentials expire during an example run?
SDK examples handle token refresh automatically. Raw HTTP examples require manual token refresh — implement a TokenManager class as shown in the OAuth 2.0 example.
Get Started

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.

20+ Production Examples
4 Languages Covered
Zero Boilerplate
Versioned With SDKs
Error Handling Included