Skip to main content
Version: Next

Flows Hub

The Flows Hub is your central location for managing API traffic and monitoring performance within the Lunar.dev ecosystem.

This hub lists the available flows under two main categories: Traffic Controls and Observability and Monitoring.

These flows help you efficiently manage your API traffic, enforce quotas, prioritize requests, and track key performance metrics.

📄️ Count LLM Tokens

The "Count LLM Tokens" processor in Lunar.dev provides an estimation of the number of tokens required for a given request body, based on a specified Language Learning Model (LLM). This estimation is performed before the request is sent to the upstream LLM provider. The estimated token count is then added as a custom header, x-lunar-estimated-tokens, to the request, which is removed by Lunar.dev before the request is actually forwarded to the LLM provider. This mechanism allows users to leverage this token estimation for internal logic within Lunar.dev, most notably in conjunction with the Custom Quota feature, enabling precise control over LLM usage based on token consumption.

📄️ Priority Queue

The Priority Queue Flow manages API requests based on their priority, ensuring high-priority traffic is handled first while maintaining smooth processing for lower-priority requests. Using the Queue processor, it controls the number of requests in the queue and assigns priorities via the x-lunar-consumer-tag header. Requests are delayed until their turn arrives or the time-to-live (TTL) expires. If the queue is full, or limits are exceeded, a 429 "Too Many Requests" response is generated.

Traffic Controls

The Traffic Controls category provides comprehensive flows designed to regulate and manage API traffic. These flows ensure optimal API performance, helping you prevent overconsumption, manage high-traffic environments, and enforce access control policies.

  • Client-Side Limiting Flow

    This flow enforces quotas within the client-side application, regulating API consumption by limiting the number of requests that can be sent. It's ideal for controlling overuse and protecting API provider resources.

  • Priority Queue Flow

    The Priority Queue Flow manages API requests based on their priority. It ensures high-priority traffic is processed first, with the ability to queue lower-priority requests until their time-to-live (TTL) expires.

  • Endpoint Access Control Flow

    This flow enforces access rules based on domain names and custom headers, allowing you to allow or block traffic from specific domains or IPs.


Observability and Monitoring

The Observability and Monitoring category allows users to define and track custom metrics for their API operations. This section is focused on providing detailed insights into API performance, usage, and rate limits, with built-in support for exporting metrics to Prometheus for real-time analysis.

  • Custom Metrics Collector Flow

    This flow enables users to define custom metrics to track specific API behaviors, such as request size or response times. Metrics can be customized using labels and exported to Prometheus for visualization in tools like Grafana and Datadog.