Skip to content

Commit ac44cf0

Browse files
[Docs] Replace custom API endpoint with OpenAPI component
1 parent 0554be3 commit ac44cf0

File tree

20 files changed

+619
-514
lines changed

20 files changed

+619
-514
lines changed

apps/portal/src/app/ai/chat/EndpointMetadata.tsx

Lines changed: 0 additions & 91 deletions
This file was deleted.

apps/portal/src/app/ai/chat/page.mdx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
import { EndpointMetadata } from "./EndpointMetadata";
2-
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@doc";
1+
import { Tabs, TabsContent, TabsList, TabsTrigger, OpenApiEndpoint } from "@doc";
32

43
# Chat API
54

6-
The thirdweb AI chat API is a standard OpenAI-compatible chat completion API that allows you to interact with the thirdweb AI model, specialized for blockchain interactions.
7-
8-
The thirdweb proprietary model is optimized for blockchain interactions and can:
5+
The thirdweb AI chat API is a standard OpenAI-compatible chat completion API that allows you to interact with the thirdweb AI model, optimized for blockchain interactions.
96

107
- Query real-time data from the blockchain
118
- Analyze transactions
129
- Fetch token balances, prices and metadata
1310
- Prepare any contract call or transaction for signing
14-
- Prepare swaps from any token pair
11+
- Prepare swaps from/to any token pair
1512
- Deploy contracts
1613
- Generate images
17-
- Search the web for information
14+
- Search the web
1815
- And more!
1916

20-
You can use the API with the API directly, or with any OpenAI-compatible client library.
17+
You can use the API with the HTTP API directly, or with any OpenAI-compatible client library.
2118

2219
<Tabs defaultValue="api">
2320
<TabsList>
2421
<TabsTrigger value="api">HTTP API</TabsTrigger>
2522
<TabsTrigger value="openai">OpenAI Client</TabsTrigger>
2623
</TabsList>
2724
<TabsContent value="api">
28-
<EndpointMetadata />
25+
<OpenApiEndpoint path="/ai/chat" method="POST" specUrl="https://api.thirdweb-dev.com/openapi.json" />
2926
</TabsContent>
3027
<TabsContent value="openai">
3128

@@ -50,4 +47,9 @@ chat_completion = client.chat.completions.create(
5047
print(chat_completion)
5148
```
5249
</TabsContent>
53-
</Tabs>
50+
</Tabs>
51+
52+
### Going further
53+
54+
- [Handle streaming responses](/ai/chat/streaming)
55+
- [Full API Reference](https://api.thirdweb-dev.com/reference#tag/ai/post/ai/chat)
File renamed without changes.

apps/portal/src/app/ai/sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export const sidebar: SideBar = {
1313
icon: <ZapIcon />,
1414
},
1515
{
16-
name: "Response Handling",
17-
href: "/ai/chat/handling-responses",
16+
name: "Streaming Responses",
17+
href: "/ai/chat/streaming",
1818
},
1919
{
2020
name: "API Reference",

apps/portal/src/app/contracts/events/page.mdx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
TabsList,
44
TabsTrigger,
55
TabsContent,
6+
OpenApiEndpoint,
67
} from "@doc";
78
import {
89
ReactIcon,
@@ -31,27 +32,7 @@ Query and listen to contract events for any deployed contract on any EVM chain.
3132
</TabsList>
3233

3334
<TabsContent value="http">
34-
### Get Contract Events
35-
36-
You can fetch contract events using the [contract events API](https://api.thirdweb.com/reference#tag/contracts/get/v1/contracts/{address}/events).
37-
38-
```http
39-
GET /v1/contracts/{address}/events?chainId=<chain_id>&decode=true
40-
Host: api.thirdweb.com
41-
x-secret-key: <project-secret-key>
42-
```
43-
44-
Authentication requires either `x-secret-key` (backend) or `x-client-id` (frontend) to be set in the request headers.
45-
46-
#### Parameters
47-
48-
- `address` - The contract address
49-
- `chainId` - The chain ID where the contract is deployed
50-
- `decode` - Whether to decode the event data (optional, defaults to false)
51-
52-
#### Response
53-
54-
The API returns a list of events that have been emitted by the specified contract, including event details and decoded function calls when `decode=true` is specified.
35+
<OpenApiEndpoint path="/v1/contracts/{chainId}/{address}/events" method="GET" />
5536

5637
</TabsContent>
5738

apps/portal/src/app/contracts/page.mdx

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
TabsList,
1111
TabsTrigger,
1212
TabsContent,
13+
OpenApiEndpoint,
1314
} from "@doc";
1415
import {
1516
ReactIcon,
@@ -67,89 +68,10 @@ Read, write, and deploy smart contracts on any EVM compatible blockchain.
6768
</TabsList>
6869

6970
<TabsContent value="http">
70-
### Read a Contract
71-
72-
You can read contract data efficiently using the [contract read API](https://api.thirdweb.com/reference#tag/contracts/post/v1/contracts/read).
73-
74-
```http
75-
GET /v1/contracts/read
76-
Host: api.thirdweb.com
77-
Content-Type: application/json
78-
x-client-id: <your-project-client-id>
79-
80-
{
81-
"chainId": "1" // your chain id
82-
"calls": [{
83-
"contractAddress": "0x...",
84-
"method": "function allowance(address owner, address spender)",
85-
"params": ["0x...", "0x..."],
86-
}],
87-
}
88-
```
89-
90-
You can batch multiple contract reads in a single request, and the response will be an array of results or errors.
91-
92-
Authentication requires either `x-secret-key` (backend) or `x-client-id` (frontend) to be set in the request headers.
93-
94-
### Write to a Contract
95-
96-
You can write to a contract using the [contract write API](https://api.thirdweb.com/reference#tag/contracts/post/v1/contracts/write).
97-
98-
<Tabs defaultValue="frontend">
99-
<TabsList>
100-
<TabsTrigger value="frontend">Frontend</TabsTrigger>
101-
<TabsTrigger value="backend">Backend</TabsTrigger>
102-
</TabsList>
10371

104-
<TabsContent value="frontend">
105-
106-
On the frontend, use your project client ID and the users's auth token to send a transaction on their behalf.
107-
108-
```http
109-
POST /v1/contracts/write
110-
Host: api.thirdweb.com
111-
Content-Type: application/json
112-
x-client-id: <your-project-client-id>
113-
Authorization: Bearer <user-auth-token>
114-
115-
{
116-
"from": "0x...", // the user wallet address
117-
"chainId": "1" // the chain id
118-
"calls": [{
119-
"contractAddress": "0x...",
120-
"method": "function transfer(address to, uint256 amount)",
121-
"params": ["0x...", "1000000000000000000"],
122-
}],
123-
}
124-
```
125-
126-
</TabsContent>
127-
128-
<TabsContent value="backend">
129-
130-
On the backend, use your project secret key to send a transaction from any of your server wallets.
131-
132-
```http
133-
POST /v1/contracts/write
134-
Host: api.thirdweb.com
135-
Content-Type: application/json
136-
x-secret-key: <your-project-secret-key>
137-
138-
{
139-
"from": "0x...", // your server wallet address
140-
"chainId": "1" // your chain id
141-
"calls": [{
142-
"contractAddress": "0x...",
143-
"method": "function transfer(address to, uint256 amount)",
144-
"params": ["0x...", "1000000000000000000"],
145-
}],
146-
}
147-
```
148-
149-
</TabsContent>
150-
</Tabs>
72+
<OpenApiEndpoint path="/v1/contracts/read" method="POST" />
15173

152-
You can batch multiple contract writes in a single request, and the transactions will be batched atomically onchain.
74+
<OpenApiEndpoint path="/v1/contracts/write" method="POST" />
15375

15476
</TabsContent>
15577

apps/portal/src/app/contracts/transactions/page.mdx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
TabsList,
44
TabsTrigger,
55
TabsContent,
6+
OpenApiEndpoint,
67
} from "@doc";
78
import {
89
EngineIcon,
@@ -21,27 +22,7 @@ Query all transactions for any deployed contract on any EVM chain.
2122
</TabsList>
2223

2324
<TabsContent value="http">
24-
### Get Contract Transactions
25-
26-
You can fetch all transactions for a contract using the [contract transactions API](https://api.thirdweb.com/reference#tag/contracts/get/v1/contracts/{address}/transactions).
27-
28-
```http
29-
GET /v1/contracts/{address}/transactions?chainId=<chain_id>&decode=true
30-
Host: api.thirdweb.com
31-
x-secret-key: <project-secret-key>
32-
```
33-
34-
Authentication requires either `x-secret-key` (backend) or `x-client-id` (frontend) to be set in the request headers.
35-
36-
#### Parameters
37-
38-
- `address` - The contract address
39-
- `chainId` - The chain ID where the contract is deployed
40-
- `decode` - Whether to decode the transaction data (optional, defaults to false)
41-
42-
#### Response
43-
44-
The API returns a list of transactions that have interacted with the specified contract, including transaction details and decoded function calls when `decode=true` is specified.
25+
<OpenApiEndpoint path="/v1/contracts/{chainId}/{address}/transactions" method="GET" />
4526

4627
</TabsContent>
4728
</Tabs>

apps/portal/src/app/page.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ArrowUpRightIcon, BotIcon, WebhookIcon, ZapIcon } from "lucide-react";
1+
import {
2+
ArrowUpRightIcon,
3+
BotIcon,
4+
MessageCircleIcon,
5+
WebhookIcon,
6+
ZapIcon,
7+
} from "lucide-react";
28
import Image from "next/image";
39
import Link from "next/link";
410
import { Heading } from "@/components/Document";
@@ -16,7 +22,6 @@ import { BridgeIcon } from "../icons/products/BridgeIcon";
1622
import { ConnectIcon } from "../icons/products/ConnectIcon";
1723
import { EngineIcon } from "../icons/products/EngineIcon";
1824
import { InsightIcon } from "../icons/products/InsightIcon";
19-
import { PlaygroundIcon } from "../icons/products/PlaygroundIcon";
2025
import DocsHeroDark from "./_images/docs-hero-dark.png";
2126
import DocsHeroLight from "./_images/docs-hero-light.png";
2227

@@ -25,7 +30,7 @@ export default function Page() {
2530
<main className="container max-w-5xl grow pb-20" data-noindex>
2631
<Hero />
2732
<div className="space-y-8">
28-
<PlaygroundSection />
33+
<AISection />
2934
<LearningResourcesSection />
3035
<ReferenceSection />
3136
</div>
@@ -70,20 +75,19 @@ function Hero() {
7075
);
7176
}
7277

73-
function PlaygroundSection() {
78+
function AISection() {
7479
return (
7580
<section>
76-
<SectionTitle anchorId="playground" title="Quick Starts" />
81+
<SectionTitle anchorId="ai" title="AI" />
7782
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
7883
<ArticleCardIndex
79-
description="Try out our interactive playground to get started"
80-
external
81-
href="https://playground.thirdweb.com"
82-
icon={PlaygroundIcon}
83-
title="Playground"
84+
description="Integrate the most advanced blockchain model into your applications"
85+
href="/ai/chat"
86+
icon={MessageCircleIcon}
87+
title="Chat API"
8488
/>
8589
<ArticleCardIndex
86-
description="For agents and humans: use the thirdweb API with natural language"
90+
description="For agents and humans. Use the thirdweb API with natural language"
8791
href="/ai/mcp"
8892
icon={BotIcon}
8993
title="MCP"

0 commit comments

Comments
 (0)