Pipes vs Endpoints
The SDK provides two main functions:definePipe()- Internal pipes for reusable SQL logic (not exposed as API)defineEndpoint()- API endpoints that can be queried from your application
Defining Endpoints
Endpoints are the most common use case - they expose your data as HTTP APIs:Defining Internal Pipes
UsedefinePipe() for reusable SQL logic that isn’t exposed as an API:
Nodes
Nodes are the building blocks of pipes. Each node is a SQL transformation:Single Node
Simple queries with one transformation:Multiple Nodes
Chain transformations together:Parameters
Define query parameters withp.* validators:
Required Parameters
Optional Parameters with Defaults
With Descriptions
SQL Templates
Use Tinybird’s template syntax to reference parameters:Basic Parameters
Type Casting
Always cast parameters to the correct type:{{DateTime(param)}}- DateTime values{{String(param)}}- String values{{Int32(param)}}- 32-bit integers{{UInt64(param)}}- Unsigned 64-bit integers{{Float64(param)}}- Floating point numbers
Default Values
Provide defaults in the template:Output Schema
Define the output schema for type safety:- Provides type inference for your client code
- Documents the API response structure
- Required for endpoints, optional for internal pipes
Endpoint Caching
Enable caching for better performance:Access Tokens
Control access to endpoints with static tokens:Complete Example
A fully-featured endpoint with multiple nodes and parameters:Type Inference
Export types for your application code:Next Steps
Materialized Views
Create real-time aggregations
Copy Pipes
Schedule periodic data snapshots