lifi.api

Documentation for eth_defi.lifi.api Python module.

LI.FI API utilities.

Helpers for interacting with the LI.FI REST API.

Functions

fetch_lifi_native_token_prices(chain_ids[, ...])

Fetch native token USD prices for multiple chains.

fetch_lifi_status(tx_hash[, from_chain_id, ...])

Fetch the status of a cross-chain transfer from the LI.FI API.

fetch_lifi_token_price_usd(chain_id[, ...])

Fetch the USD price of a token using the LI.FI token endpoint.

get_lifi_api_url()

Get LI.FI API base URL.

get_lifi_headers()

Get HTTP headers for LI.FI API requests.

Exceptions

LifiAPIError

Error returned by LI.FI API.

exception LifiAPIError

Bases: Exception

Error returned by LI.FI API.

__init__(*args, **kwargs)
__new__(**kwargs)
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

get_lifi_api_url()

Get LI.FI API base URL.

Returns

LI.FI API endpoint URL

Return type

str

get_lifi_headers()

Get HTTP headers for LI.FI API requests.

Reads the optional LIFI_API_KEY environment variable. If not set, logs a warning and returns headers without authentication. Without an API key, the rate limit is 10 requests per second.

Returns

Headers dict, possibly containing x-lifi-api-key

Return type

dict

fetch_lifi_token_price_usd(chain_id, token_address='0x0000000000000000000000000000000000000000', api_timeout=30)

Fetch the USD price of a token using the LI.FI token endpoint.

Uses GET /v1/token which returns priceUSD for any supported token.

Parameters
  • chain_id (int) – Chain ID (e.g. 1 for Ethereum, 42161 for Arbitrum)

  • token_address (str) – Token contract address. Defaults to native token (zero address).

  • api_timeout (float) – API request timeout in seconds

Returns

Token price in USD

Raises

LifiAPIError – If the API returns an error or price is unavailable

Return type

decimal.Decimal

fetch_lifi_status(tx_hash, from_chain_id=None, to_chain_id=None, api_timeout=30)

Fetch the status of a cross-chain transfer from the LI.FI API.

Uses GET /v1/status to check whether a bridge transaction has been delivered on the destination chain.

The response contains a status field with one of:

  • PENDING — transfer in progress

  • DONE — transfer completed successfully

  • FAILED — transfer unsuccessful

  • NOT_FOUND — transaction hash not recognised yet

  • INVALID — hash not tied to a known bridge

Parameters
  • tx_hash (str) – Transaction hash on the source chain (hex string)

  • from_chain_id (int | None) – Source chain ID (speeds up lookup)

  • to_chain_id (int | None) – Destination chain ID (speeds up lookup)

  • api_timeout (float) – API request timeout in seconds

Returns

Full status response dict from LI.FI API

Raises

LifiAPIError – If the HTTP request fails

Return type

dict

fetch_lifi_native_token_prices(chain_ids, api_timeout=30)

Fetch native token USD prices for multiple chains.

Makes one API call per chain to the LI.FI token endpoint.

Parameters
  • chain_ids (list[int]) – List of chain IDs to fetch prices for

  • api_timeout (float) – API request timeout in seconds per request

Returns

Dict mapping chain_id to native token price in USD

Raises

LifiAPIError – If any API call fails

Return type

dict[int, decimal.Decimal]