Skip to main content

Posts

Showing posts with the label API Integration

Implementing Server-Sent Events (SSE) for Perplexity API Streaming in Python

  You trigger a standard REST request to the Perplexity API, expecting a quick JSON response. Instead, your Python script hangs. Five seconds pass. Ten seconds. Finally, either a massive payload dumps all at once, or your load balancer severs the connection due to a timeout. This behavior isn't a bug in the API; it is a mismatch in consumption patterns. Perplexity, like most modern LLM providers, relies on Server-Sent Events (SSE) to deliver tokens as they are generated. If you treat this connection like a standard synchronous HTTP request, you are blocking I/O until the entire generation is complete. This article details the root cause of this latency and provides a production-grade Python implementation to handle Perplexity's streaming data correctly. The Root Cause: HTTP Buffering vs. Event Streams To understand why standard requests fail (or appear to lag), we must look at the underlying transport mechanism. The Blocking Model In a typical HTTP interactions (e.g.,  request...

Why Stripe Subscriptions Get Stuck in "Incomplete" Status

  You have built your pricing page, set up your backend endpoint, and executed   stripe.subscriptions.create . You expect the subscription object to return with   status: 'active' . Instead, the API returns  status: 'incomplete' . This is one of the most common frustration points for engineers integrating Stripe Billing. It breaks your provisioning logic because your system assumes the user has paid, but Stripe says they haven't. If you try to force the charge, it fails. If you ignore it, you have "zombie" subscriptions in your dashboard that never collect revenue. This article explains strictly why this happens within the Stripe state machine and provides the modern, SCA-compliant architecture to handle it correctly. The Root Cause: SCA and The First Invoice To understand why your subscription is "incomplete," you must look at the underlying  PaymentIntent . When you create a subscription, Stripe immediately generates the first invoice. Attempti...