GraphQL API
Sandbox
Explore the API and discover available queries, mutations, and types in the interactive sandbox: api.sapience.xyz/graphql
The sandbox includes full schema documentation, autocomplete, and lets you run queries directly in your browser.
Endpoint
https://api.sapience.xyz/graphqlTypeScript types
The SDK exports all GraphQL types for use in your TypeScript projects:
import type {
Category,
Question,
Condition,
} from '@sapience/sdk/types/graphql';View the full type definitions on GitHub: packages/sdk/types/graphql.ts.
Quick example
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
const client = new ApolloClient({
uri: 'https://api.sapience.xyz/graphql',
cache: new InMemoryCache(),
});
const { data } = await client.query({
query: gql`
query Questions {
questions(take: 10, sortField: endTime, sortDirection: desc) {
questionType
predictionCount
condition {
id
endTime
}
group {
id
}
}
}
`,
});
console.log(data.questions);Notes
- The API is currently public; please be considerate and cache when possible.
- Use
slug(notid) when you need a stable, human-friendly identifier — most ID fields on Sapience entities areInt!and shift between environments. - Pagination args vary by query. The Prisma-backed list queries (
categories,conditions,conditionGroups, etc.) acceptcursor,distinct,orderBy,skip,take,where. Curated queries (questions, leaderboard queries) take a smaller fixed set — check the sandbox before assuming. - Some queries are marked
@deprecatedin the schema (accountAccuracy,accountProfitRank,claims,closes,conditionGroup,pickConfiguration,protocolVolume,tradeCount,users). They still respond, but rely on them at your own risk — read the schema before depending on one.