DefiLlama: Get the closest block to a timestamp
Retrieve the closest block to a timestamp with the DeFiLlama API. The request takes a chain and a timestamp. Use it in financial research or market monitoring. Use the response in a DeFi workflow for the selected protocol, and compare the request and response with the provider example.
- Selected price
- $0 / callPublished pricing
- Sellers / APIs
- 1 / 1
- Requests · 30d
- —Loading...
- Success rate · 30d
- —Loading...
DefiLlama: Get the closest block to a timestamp
Prepare your request, then continue with your agent.
Selected price
$0 / call
- Provider
- API
- Pricing
On this page
Playground
Run sends a real API request. Charges follow the published API contract.
Response structure
heightintegertimestampinteger
// Inferred from response examples. Fields are optional and other fields may be returned.
export type ApiResponse = {
height?: number;
timestamp?: number;
};Sellers
| Seller | Pricing | Requests · 30d | Performance | Access |
|---|---|---|---|---|
defillamaCurrent DefiLlama — Get the closest block to a timestamp · GET · View API reference | $0 / call | — | —successP50— |
- Unit price
- $0
Statistics use persisted gateway logs from the last 30 days up to now, including today.
Success rate = successful requests / all requests;
P50 = median latency of successful requests.
Prices reflect the published API contract. Contract revision: 4. Price update time: not supplied.
Total $0
API
- Method
- GET
- Endpoint
https://api.openany.si/v1/agent-apis/defillama/block/{chain}/{timestamp}- Content type
- application/json
- Authentication
Authorization: Bearer $OPENANY_API_KEY
curl \
'https://api.openany.si/v1/agent-apis/defillama/block/ethereum/1603964988' \
-X GET \
-H "Authorization: Bearer $OPENANY_API_KEY" \
-H 'Content-Type: application/json'Input parameters
Fields in this listing; additional options and input encoding can vary by provider.
| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
chain | URL path parameterspath | string | Yes | Chain which you want to get the block from |
timestamp | URL path parameterspath | integer | Yes | UNIX timestamp of the block you are searching for |
Required markers inside a nested object or variant apply when that object or variant is used.
Sample response
Sample response · Documented HTTP 200 Published documentation example. Verify the actual response after an approved call.
{
"height": 11150916,
"timestamp": 1603964988
}Agent integration
Copy the resource contract without sharing an API key.
View API Markdown
# DefiLlama: Get the closest block to a timestamp
Retrieve the closest block to a timestamp with the DeFiLlama API. The request takes a chain and a timestamp. Use it in financial research or market monitoring. Use the response in a DeFi workflow for the selected protocol, and compare the request and response with the provider example.
## Available implementations
defillama · DefiLlama — Get the closest block to a timestamp: https://openany.si/markets/apis/capabilities/defillama-get-the-closest-block-to-a-timestamp?offering=1975301c-d271-4002-aa64-997e16655479 · $0 / call
## Selected API contract
Documentation: https://openany.si/apis/1975301c-d271-4002-aa64-997e16655479
Method: GET
Endpoint: https://api.openany.si/v1/agent-apis/defillama/block/{chain}/{timestamp}
Price: $0 / call
Provider: defillama
Contract revision: 4
Price source: OpenAny public API contract and documented provider unit rates. Price update time: not supplied.
Use OPENANY_API_KEY from the environment. API Key calls use your shared balance.
## Prepared request
```bash
curl \
'https://api.openany.si/v1/agent-apis/defillama/block/ethereum/1603964988' \
-X GET \
-H "Authorization: Bearer $OPENANY_API_KEY" \
-H 'Content-Type: application/json'
```
## API contract
```json
{
"resource_type": "api",
"name": "DefiLlama — Get the closest block to a timestamp",
"endpoint": "https://api.openany.si/v1/agent-apis/defillama/block/{chain}/{timestamp}",
"method": "GET",
"content_type": "none",
"execution_mode": "sync",
"authentication": {
"type": "bearer",
"environment_variable": "OPENANY_API_KEY"
},
"inputs": [
{
"description": "Chain which you want to get the block from",
"location": "path",
"name": "chain",
"nullable": false,
"required": true,
"type": "string"
},
{
"description": "UNIX timestamp of the block you are searching for",
"location": "path",
"name": "timestamp",
"nullable": false,
"required": true,
"type": "integer"
}
],
"billing": {
"currency": "USD",
"mode": "fixed",
"priceMicroUsd": "0",
"rounding": null,
"unit": "call",
"unitQuantity": null
},
"examples": [
{
"http_status": 200,
"name": "Official UI example (not runtime verified)",
"request": {
"body": null,
"headers": {},
"path": {
"chain": "ethereum",
"timestamp": 1603964988
},
"query": {}
},
"response_body": {
"height": 11150916,
"timestamp": 1603964988
}
}
]
}
```Error handling
| Status | Next step |
|---|---|
400 | Check the offering and request fields. |
401 / 403 | Verify your credentials and access permissions. |
402 | Inspect the selected access mode and returned payment requirements. |
429 | Respect the returned rate limit and retry guidance. |
5xx | Inspect the error and usage record before retrying a paid operation. |
Examples
Official UI example (not runtime verified)
Published documentation example. Verify the actual response after an approved call.
Prepare your environment
Use a terminal with cURL installed.
Use an OpenAny API key with shared-balance access. Confirm availability and price before running; a call may charge your balance.
Set the key in your terminal using the hidden prompt below. Keep its value out of source files and logs.
Terminal · macOS / Linuxprintf 'OpenAny API key: ' read -r -s OPENANY_API_KEY export OPENANY_API_KEY printf '\n'Run the request
Paste the complete command below into your terminal.
Values to replace before running 2
Review these request fields before running. Keep the published provider and request method unchanged.
chain- Chain which you want to get the block from
timestamp- UNIX timestamp of the block you are searching for
Terminal · cURLcurl \ 'https://api.openany.si/v1/agent-apis/defillama/block/ethereum/1603964988' \ -X GET \ -H "Authorization: Bearer $OPENANY_API_KEY" \ -H 'Content-Type: application/json'Check the response
Sample response · Documented HTTP 200
Sample response{ "height": 11150916, "timestamp": 1603964988 }