How-to guide

How to Choose Which Turns Show Ads in FastAPI

This guide shows how to choose which turns show ads in a FastAPI app, the goal being to control ad placement and frequency across a conversation. It builds on the Monetzly gRPC service (no Python SDK exists for this stack), so the approach is specific to how FastAPI produces and streams responses.

Overview

Not every turn in a FastAPI conversation should carry an ad. Placement and frequency shape both revenue and user experience: too many ads erodes trust, too few leaves revenue on the table.

You control this by deciding which responses you route through injection — for example, skipping very short replies or the first turn, and allowing ads on substantive answers where a recommendation is genuinely useful.

FastAPI apps are usually built for LLM API backends, SSE/streaming chat endpoints, and agent microservices, so choose which turns show ads typically comes up while a user is mid-conversation, the moment where monetization has to be additive rather than disruptive.

How this works on FastAPI

There is no official Monetzly Python SDK — the package is Node-only. The supported path for a Python stack is the gRPC service the package ships as tps_alter.proto: generate Python stubs and open a ProcessStream bidi call (StartRequest, then a TokenRequest per LLM token, then StopRequest), reading back the ad-injected TokenResponses. Alternatively, run a tiny Node sidecar that uses the SDK and stream tokens to it. Either way, confirm the auth handshake for non-JS clients before publishing.

Since FastAPI is a Python stack with no official SDK, this task runs through the shipped tps_alter.proto gRPC service (or a Node sidecar); the auth handshake for a direct client is still TODO_VERIFY.

Steps

  1. Decide your policy: which FastAPI turns are ad-eligible (e.g. skip trivial or first replies).
  2. Route only eligible turns through the injection call.
  3. Measure revenue and engagement, then adjust frequency.

Frequently asked questions

Start monetizing in about 5 minutes

Wrap your existing LLM response stream with the Monetzly SDK and earn on every session, no paywall required.

Related