Overview
TinybirdApi is a low-level API wrapper that provides direct access to Tinybird’s REST API. It is intentionally decoupled from the typed TinybirdClient layer, allowing you to use it standalone with just a baseUrl and token.
This class is useful when you need:
- Direct API access without type definitions
- Dynamic queries without compile-time type checking
- A lightweight wrapper for scripting or automation
- To integrate Tinybird into existing codebases without adopting the full SDK
Constructor
TheTinybirdApi class is typically created using the createTinybirdApi() function:
Methods
query()
Query a Tinybird API endpoint (pipe) with optional parameters.Parameters
The name of the pipe endpoint to query
Query parameters to pass to the endpoint. Array values are sent as multiple query parameters with the same key.
Additional options:
token: Optional token override for this requesttimeout: Request timeout in millisecondssignal: AbortSignal for cancellation
Example
Important: Do not pass
Date objects as query parameters. Use strings in formats like YYYY-MM-DD or YYYY-MM-DD HH:MM:SS instead.ingest()
Ingest a single row of data into a datasource.Parameters
The name of the datasource to ingest data into
The row data to ingest. Must match your datasource schema.
Additional options:
token: Optional token override for this requestwait: Whether to wait for data to be committed (default:true)timeout: Request timeout in millisecondssignal: AbortSignal for cancellation
Example
Important: Do not pass
Date objects in the event payload. Use strings in formats like YYYY-MM-DD HH:MM:SS instead.ingestBatch()
Ingest multiple rows of data into a datasource in a single request.Parameters
The name of the datasource to ingest data into
Array of row data to ingest. Each row must match your datasource schema.
Same options as
ingest()Example
sql()
Execute raw SQL queries against Tinybird.Parameters
The SQL query to execute
Additional options:
token: Optional token override for this requesttimeout: Request timeout in millisecondssignal: AbortSignal for cancellation
Example
appendDatasource()
Append data to a datasource from a remote URL or local file.Parameters
The name of the datasource to append data to
Source options:
url: Remote URL to a CSV, NDJSON, or Parquet file (mutually exclusive withfile)file: Local file path (mutually exclusive withurl)csvDialect: Optional CSV parsing options (delimiter, newLine, escapeChar)timeout: Request timeout in millisecondssignal: AbortSignal for cancellation
Additional options:
mode:"append"(default) or"replace"to replace all existing datatoken: Optional token override for this request
Example
The format (CSV, NDJSON, Parquet) is automatically detected from the file extension.
deleteDatasource()
Delete rows from a datasource that match a SQL condition.Parameters
The name of the datasource to delete rows from
Delete options:
deleteCondition: SQL WHERE clause to match rows (required)dryRun: Preview deletion without executing (optional)timeout: Request timeout in millisecondssignal: AbortSignal for cancellation
Additional options:
token: Optional token override for this request
Example
truncateDatasource()
Remove all rows from a datasource.Parameters
The name of the datasource to truncate
timeout: Request timeout in millisecondssignal: AbortSignal for cancellation
Additional options:
token: Optional token override for this request
Example
createToken()
Create a scoped token using the Tinybird Token API. Supports both static tokens and JWT tokens.Parameters
Token configuration:
name: Token name/identifierscopes: JWT-style scope objects (array of{ type, resource?, fixed_params?, filter? })scope: Static-token scope strings (string or string array)limits: Optional rate-limiting config ({ rps?: number })
Additional options:
expirationTime: Optional expiration time for JWT tokens (Unix timestamp)token: Optional token override for this requesttimeout: Request timeout in millisecondssignal: AbortSignal for cancellation
Example
request()
Execute a low-level HTTP request against the Tinybird API.Parameters
The API path (e.g.,
/v1/workspace)Standard
RequestInit options plus:token: Optional token override for this request
Example
requestJson()
Execute a request and automatically parse the JSON response.Parameters
The API path (e.g.,
/v1/workspace)Standard
RequestInit options plus:token: Optional token override for this request
Example
Error Handling
All methods throwTinybirdApiError when the API returns a non-OK response:
Token Override
Most methods support per-request token override, useful for:- Multi-tenant applications with different tokens per user
- Testing with different permission levels
- Using branch-specific tokens
Related
createTinybirdApi()
Factory function to create a TinybirdApi instance
Tinybird Client
Type-safe client with schema definitions