1+ import { createMetadata } from " @doc" ;
2+
3+ export const metadata = createMetadata ({
4+ image: {
5+ title: " API Reference" ,
6+ icon: " nebula" ,
7+ },
8+ title: " thirdweb Nebula API Reference" ,
9+ description:
10+ " Explore the thirdweb Nebula API reference to unlock the most powerful AI to interact with the blockchain and start building AI powered web3 apps." ,
11+ });
12+
113# Nebula API Reference
214
315Nebula provides a conversational interface to interact with blockchain data and services, and access to thirdweb tools.
@@ -13,7 +25,9 @@ https://nebula-api.thirdweb.com
1325
1426## Authentication
1527
16- All API endpoints require authentication using the thirdweb secret key. Include this key in your request headers:
28+ All API endpoints require authentication using the thirdweb secret key. [ Learn how to obtain a secret key.] ( /nebula/get-started ) .
29+
30+ Include this key in your request headers:
1731
1832``` bash
1933x-secret-key: YOUR_THIRDWEB_SECRET_KEY
@@ -31,161 +45,7 @@ curl -X POST https://nebula-api.thirdweb.com/chat \
3145 }'
3246```
3347
34- ## Sessions
35-
36- Sessions maintain conversation threads with the AI and can be:
37-
38- - Created explicitly via the ` /session ` endpoint
39- - Created automatically when sending a message without a session_id
40- - Reused to maintain context across multiple messages
41- - Configured with specific execution parameters
42-
43- Sessions persist your conversation history and custom configurations for blockchain data and thirdweb tools interactions.
44-
45- ## Context Filters
46-
47- Control what blockchain data informs AI responses through context filtering:
48-
49- ``` json
50- {
51- "context" : {
52- "chain_ids" : [" 1" ], // comma delimited list of chain ID's
53- "wallet_address" : " 0x..." // wallet address
54- }
55- }
56- ```
57-
58- Benefits:
59- - Filter by blockchain networks using chain IDs
60- - Target specific contract addresses
61- - Target specific wallet addresses
62- - Control context scope for relevant responses
63- - Optimize token usage and response relevance
64-
65- ## Execute Configuration
66-
67- Configure transaction execution behavior using the execute config:
68-
69- ``` json
70- {
71- "execute_config" : {
72- "mode" : " client" ,
73- "signer_wallet_address" : " 0x..."
74- }
75- }
76- ```
77-
78- Parameters:
79- - ` mode ` : Execution mode (currently supports "client")
80- - ` signer_wallet_address ` : Wallet address for transaction signing
81-
82- When mode is "client", Nebula returns an unsigned transaction for local wallet signing.
83-
84- ## Response Handling
85-
86- Nebula API supports two types of response modes: streaming and non-streaming. The mode is controlled by the ` stream ` parameter in your request.
87-
88- ### Non-Streaming Responses
89-
90- When ` stream: false ` , the API returns a single JSON response:
91-
92- ``` json
93- {
94- "result" : {
95- "message" : " The last 5 blocks on polygon are..." ,
96- "session_id" : " abc" ,
97- "message_id" : " 1234"
98- }
99- }
100- ```
101-
102- ### Streaming Responses
103-
104- When ` stream: true ` , the API uses Server-Sent Events (SSE) to stream the response. You'll need to handle the following event types:
105-
106- 1 . ` init ` : Initializes the stream and provides session information
107- 2 . ` presence ` : Provides backend status updates about worker processing
108- 3 . ` action ` : Contains blockchain transaction or action data
109- 4 . ` delta ` : Contains chunks of the response message text
110- 5 . ` error ` : Contains error information if something goes wrong
111-
112- ** Example SSE Stream:**
113- ``` tsx
114- event : init
115- data : {
116- " session_id" : " f4b45429-9570-4ee8-8c8f-8b267429915a" ,
117- " request_id" : " 9efc7f6a-8576-4d9c-8603-f6c72aa72164" ,
118- " type" : " init" ,
119- " source" : " user" ,
120- " data" : " "
121- }
122-
123- event : presence
124- data : {
125- " session_id" : " f4b45429-9570-4ee8-8c8f-8b267429915a" ,
126- " request_id" : " 9efc7f6a-8576-4d9c-8603-f6c72aa72164" ,
127- " type" : " presence" ,
128- " source" : " executor" ,
129- " data" : " Performing function execution: ExecuteNativeTransferClientSigning"
130- }
131-
132- event : action
133- data : {
134- " session_id" : " f4b45429-9570-4ee8-8c8f-8b267429915a" ,
135- " request_id" : " 9efc7f6a-8576-4d9c-8603-f6c72aa72164" ,
136- " type" : " sign_transaction" ,
137- " source" : " executor" ,
138- " data" : " {\" chainId\" : 11155111, \" to\" : \" 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\" , \" data\" : \" 0x\" , \" value\" : \" 0x5af3107a4000\" }"
139- }
140-
141- event : delta
142- data : {" v" : " To send 0.0001 ETH on the Sepolia network" }
143-
144- event : delta
145- data : {" v" : " to the address associated with" }
146- ```
147-
148- ** JavaScript Example for Handling Streams:**
149- ``` javascript
150- const eventSource = new EventSource (' /chat' , {
151- headers: {
152- ' x-secret-key' : ' YOUR_THIRDWEB_SECRET_KEY'
153- }
154- });
15548
156- let messageText = ' ' ;
157-
158- eventSource .addEventListener (' init' , (event ) => {
159- const data = JSON .parse (event .data );
160- console .log (' Stream initialized:' , data);
161- });
162-
163- eventSource .addEventListener (' presence' , (event ) => {
164- const data = JSON .parse (event .data );
165- console .log (' Backend status:' , data .data );
166- });
167-
168- eventSource .addEventListener (' action' , (event ) => {
169- const data = JSON .parse (event .data );
170- console .log (' Received action:' , data);
171- if (data .type === ' sign_transaction' ) {
172- // Handle transaction signing
173- handleTransaction (data);
174- }
175- });
176-
177- eventSource .addEventListener (' delta' , (event ) => {
178- const data = JSON .parse (event .data );
179- messageText += data .v ;
180- console .log (' Current message:' , messageText);
181- });
182-
183- eventSource .addEventListener (' error' , (event ) => {
184- const error = JSON .parse (event .data );
185- console .error (' Error:' , error);
186- eventSource .close ();
187- });
188- ```
18949
19050
19151
0 commit comments