Bitquery

Learn how to use Bitquery with Composio

Overview

SLUG: BITQUERY

Description

Bitquery provides historical and real-time indexed data for over 40 blockchains through GraphQL APIs, Websockets, SQL, and cloud providers.

Authentication Details

generic_api_key
stringRequired

Connecting to Bitquery

Create an auth config

Use the dashboard to create an auth config for the Bitquery toolkit. This allows you to connect multiple Bitquery accounts to Composio for agents to use.

1

Select App

Navigate to the Bitquery toolkit page and click “Setup Integration”.

2

Configure Auth Config Settings

Select among the supported auth schemes of and configure them here.

3

Create and Get auth config ID

Click “Create Integration”. After creation, copy the displayed ID starting with ac_. This is your auth config ID. This is not a sensitive ID — you can save it in environment variables or a database. This ID will be used to create connections to the toolkit for a given user.

Connect Your Account

Using API Key

1from composio import Composio
2from composio.types import auth_scheme
3
4# Replace these with your actual values
5bitquery_auth_config_id = "ac_YOUR_BITQUERY_CONFIG_ID" # Auth config ID created above
6user_id = "0000-0000-0000" # UUID from database/app
7
8composio = Composio()
9
10def authenticate_toolkit(user_id: str, auth_config_id: str):
11 # Replace this with a method to retrieve an API key from the user.
12 # Or supply your own.
13 user_api_key = input("[!] Enter API key")
14
15 connection_request = composio.connected_accounts.initiate(
16 user_id=user_id,
17 auth_config_id=auth_config_id,
18 config={"auth_scheme": "API_KEY", "val": user_api_key}
19 )
20
21 # API Key authentication is immediate - no redirect needed
22 print(f"Successfully connected Bitquery for user {user_id}")
23 print(f"Connection status: {connection_request.status}")
24
25 return connection_request.id
26
27
28connection_id = authenticate_toolkit(user_id, bitquery_auth_config_id)
29
30# You can verify the connection using:
31connected_account = composio.connected_accounts.get(connection_id)
32print(f"Connected account: {connected_account}")

Tools

Executing tools

Python
1from composio import Composio
2from openai import OpenAI
3import json
4
5openai = OpenAI()
6composio = Composio()
7
8# User ID must be a valid UUID format
9user_id = "0000-0000-0000" # Replace with actual user UUID from your database
10
11tools = composio.tools.get(user_id=user_id, toolkits=["BITQUERY"])
12
13print("[!] Tools:")
14print(json.dumps(tools))
15
16def invoke_llm(task = "What can you do?"):
17 completion = openai.chat.completions.create(
18 model="gpt-4o",
19 messages=[
20 {
21 "role": "user",
22 "content": task, # Your task here!
23 },
24 ],
25 tools=tools,
26 )
27
28 # Handle Result from tool call
29 result = composio.provider.handle_tool_calls(user_id=user_id, response=completion)
30 print(f"[!] Completion: {completion}")
31 print(f"[!] Tool call result: {result}")
32
33invoke_llm()

Tool List

Tool Name: Combined Database Query

Description

Tool to query the combined database, which merges archive and real-time databases. use when you need both historical and up-to-the-second blockchain data in one request.

Action Parameters

operationName
string
query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired

Tool Name: Aliases Metric

Description

Tool to use graphql aliases to rename fields in the response for clarity and disambiguation. use when you need to query multiple metrics with identical field names in one call.

Action Parameters

query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired

Tool Name: Archive Database Query

Description

Tool to query the archive database. use when you need full historical blockchain data (delayed by tens of minutes to hours).

Action Parameters

operationName
string
query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired

Tool Name: Conditional Metrics Snippet

Description

Tool to generate a graphql metric snippet with conditional logic. use when you need to apply filters directly on metric calculations via the `if` attribute.

Action Parameters

alias
string
distinct_field
string
field
stringRequired
if
objectRequired
operation
stringRequired
select_where
object

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Count Distinct Metric

Description

Tool to use the count distinct metric to aggregate unique values for a field. use when you need to count the number of unique occurrences in a dataset.

Action Parameters

query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired

Tool Name: Count Metric

Description

Tool to use the count metric to aggregate the number of records matching a graphql query. use when you need simple record counts.

Action Parameters

query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired

Tool Name: Database Selection

Description

Tool to select the database (archive, realtime, combined) to query at the top level of a graphql request. use after determining whether you need live, historical, or combined blockchain data.

Action Parameters

dataset
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Early Access Program Query

Description

Tool to access streaming data across various blockchain networks for evaluation purposes. use when querying chains not available via the v2 endpoint; limited to real-time data only.

Action Parameters

query
stringRequired
variables
object

Action Response

data
objectRequired
error
string
errors
array
successful
booleanRequired

Tool Name: Mempool Subscription

Description

Tool to subscribe to real-time mempool updates for evm chains (ethereum, bnb, etc.). use after constructing your graphql subscription to stream pending transactions live.

Action Parameters

query
stringRequired
variables
object

Action Response

data
objectRequired
error
string
errors
array
successful
booleanRequired

Tool Name: Network Selection

Description

Tool to select the blockchain network for graphql queries. use before constructing dataset or metric queries to ensure the correct chain is targeted.

Action Parameters

network
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Options Query

Description

Tool to fetch graphql dataset options via schema introspection. use when you need to discover root-level query fields and their arguments before building queries.

Action Parameters

Action Response

data
objectRequired
error
string
errors
array
successful
booleanRequired

Tool Name: Price Asymmetry Metric

Description

Tool to generate graphql priceasymmetry filter snippet. use when you need to filter trades based on price asymmetry metric.

Action Parameters

ge
number
gt
number
le
number
lt
number

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Quantile Metric

Description

Tool to calculate quantiles to understand the distribution of numerical data. use when you need percentile metrics (e.g., median or quartiles) of a numerical field in a dataset.

Action Parameters

query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired

Tool Name: Realtime Database Query

Description

Realtime database query

Action Parameters

operationName
string
query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired

Tool Name: Select By Metric

Description

Tool to generate a graphql metric snippet filtering by its value using selectwhere. use when you need to include only metrics meeting specific value conditions (e.g., only positive sums).

Action Parameters

alias
string
of
stringRequired
operation
stringRequired
selectWhere
objectRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Statistics Metric

Description

Tool to compute statistical metrics (mean, median, etc.) over one variable in a dataset. use when you need precise summary statistics in your graphql query.

Action Parameters

query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired

Tool Name: Sum Metric

Description

Tool to calculate the sum of a specified field's values across defined dimensions. use when you need to aggregate total values in a dataset.

Action Parameters

query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired

Tool Name: Uniq Metric

Description

Tool to estimate the count of unique values using the uniq metric. use when you need approximate or exact unique counts for analytics on blockchain datasets.

Action Parameters

query
stringRequired
variables
object

Action Response

data
object
error
string
errors
array
successful
booleanRequired