The topspin API
The topspin API runs queries over HTTP and returns typed answers, or diagnostics that say where in the source the problem is. This page is generated from the OpenAPI document, which any OpenAPI 3.0 generator can turn into a client for your language.
The API is served by the topspin you sign in to, under /api. There is no public
host, so the examples here use a placeholder, https://topspin.example/api: replace
topspin.example with the host you open topspin at. The settings page gives you
the token URL along with each key.
Getting started
- On topspin, open Settings → API keys → Create key. The secret is shown once. The key’s owner needs beta access.
- Trade the key for an access token. It lasts an hour; get a new one rather than refreshing it.
- Send the token as
Authorization: Bearer …with each request.
curl -s https://topspin.example/api/v1/token \
-H 'Content-Type: application/json' \
-d '{"clientId": "topspin-api-…", "clientSecret": "…"}'
curl -s https://topspin.example/api/v1/queries/run \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-d '{"source": "from nfl.teams\n where season = 2025\n select team, points_for\n limit 5"}'
A query that cannot run answers 422 with its diagnostics. 400 means the request body did not match the schema, and is never about the query.
Operations
POST /v1/token
Exchange an API key for an access token. Posts the key's client credentials to Keycloak's token endpoint and returns the access token it issues. Identical to calling that endpoint yourself (see the keycloakClientCredentials security scheme). Tokens are not refreshable: fetch a new one when expiresIn runs out.
Needs no access token. Request body: TokenRequest
| Status | Body | Meaning |
|---|---|---|
| 200 | TokenResponse | A Keycloak access token for the topspin API. |
| 400 | ApiError | The request body does not match the schema. Never about the query text — see 422. |
| 401 | ApiError | No access token, or one that was not accepted: expired, for another audience, or for a revoked key. |
| 500 | ApiError | Something failed on topspin's side. |
| 503 | ApiError | The authorization server or the database is not reachable. |
GET /v1/me
Who the access token acts for.
Needs an access token.
| Status | Body | Meaning |
|---|---|---|
| 200 | Principal | Who an access token acts for. |
| 400 | ApiError | The request body does not match the schema. Never about the query text — see 422. |
| 401 | ApiError | No access token, or one that was not accepted: expired, for another audience, or for a revoked key. |
| 403 | ApiError | The API key's owner is not approved for the topspin beta. |
| 500 | ApiError | Something failed on topspin's side. |
| 503 | ApiError | The authorization server or the database is not reachable. |
POST /v1/queries/run
Run a query. Parses, resolves and runs the source, and returns the answer. Nothing is saved. A query that cannot run as written answers 422 with every problem located in the source.
Needs an access token. Request body: QueryRequest
| Status | Body | Meaning |
|---|---|---|
| 200 | QueryResult | A query's answer. |
| 400 | ApiError | The request body does not match the schema. Never about the query text — see 422. |
| 401 | ApiError | No access token, or one that was not accepted: expired, for another audience, or for a revoked key. |
| 403 | ApiError | The API key's owner is not approved for the topspin beta. |
| 422 | QueryRejected | The query cannot run as written. Every diagnostic is located in the source and fixable by editing it. |
| 500 | ApiError | Something failed on topspin's side. |
| 503 | ApiError | The authorization server or the database is not reachable. |
POST /v1/queries/validate
Check a query without running it. Parses the source and resolves every name in it against the datasets, exactly as the editor does while you type. Nothing is executed. Always 200 for a well-formed request; read valid and diagnostics.
Needs an access token. Request body: QueryRequest
| Status | Body | Meaning |
|---|---|---|
| 200 | ValidationResult | What checking a query without running it found. |
| 400 | ApiError | The request body does not match the schema. Never about the query text — see 422. |
| 401 | ApiError | No access token, or one that was not accepted: expired, for another audience, or for a revoked key. |
| 403 | ApiError | The API key's owner is not approved for the topspin beta. |
| 500 | ApiError | Something failed on topspin's side. |
| 503 | ApiError | The authorization server or the database is not reachable. |
Types
ApiError
A request that was refused for a reason other than the query text: a malformed body, a missing or rejected token, an account without beta access, or a failure on topspin's side.
| Field | Type | About |
|---|---|---|
code | ApiErrorCode | |
message | string |
ApiErrorCode
One of bad_request, unauthorized, forbidden, not_found, unavailable, internal.
Cell
One value. kind says which of the value fields is set; none is set when kind is null.
| Field | Type | About |
|---|---|---|
booleanValue | boolean | Optional. |
kind | CellKind | |
numberValue | number | Optional. |
stringValue | string | Optional. |
CellKind
One of null, string, number, boolean.
Column
| Field | Type | About |
|---|---|---|
align | ColumnAlign | |
caveat | string | Optional. |
description | string | Optional. The glossary's sentence for the stat. |
format | ColumnFormat | |
hint | string | Optional. The sentence the query wrote for this heading with hint. |
key | string | The column's name in the query language. |
label | string |
ColumnAlign
One of left, right.
ColumnFormat
One of integer, decimal, decimal2, decimal3, percentage, percentage_whole, batting_avg, era, text.
ColumnPair
| Field | Type | About |
|---|---|---|
guest | string | |
host | string |
ComparisonOperator
One of equal, notEqual, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual.
Diagnostic
One problem with a query. range is where in the source it is, and is absent when the problem is about no part of the text, such as a dataset that could not be read.
| Field | Type | About |
|---|---|---|
code | DiagnosticCode | |
message | string | |
range | Range | Optional. |
subject | string | Optional. The name the problem is about, as written: a column, a dataset, a composite(...) call. |
DiagnosticCode
One of SyntaxError, UnknownLeague, UnknownDataset, UnknownField, DimensionUnavailable, BadValue, BadOperator, NotFilterable, NotSortable, OutOfCoverage, BadLimit, PercentileNeedsPopulation, BadComposite, BadRatio, BadPercentile, BadStanding, BadFormat, BadAsOf, BadCalc, BadPivot, BadStage, BadAlias, BadBenchmark, BadSpan, NotGrouped, NotGroupable, AggregateInWhere, ValueInHaving, BadPair, BadHint, HighlightNotSelected, KeepNotSelected, ExecutionFailed, HandlerMissing.
HighlightCondition
| Field | Type | About |
|---|---|---|
column | string | |
operator | ComparisonOperator | |
value | Cell |
HighlightRule
One highlight line. A row is highlighted when every condition of some rule holds.
| Field | Type | About |
|---|---|---|
conditions | HighlightCondition[] |
OrderedBy
| Field | Type | About |
|---|---|---|
direction | SortDirection | |
key | string |
Pivot
How the answer was read as a matrix by pivot by.
| Field | Type | About |
|---|---|---|
by | string | |
headings | string[] | |
label | string |
Position
| Field | Type | About |
|---|---|---|
column | integer | 1-based column, in UTF-16 code units. |
line | integer | 1-based line. |
offset | integer | 0-based UTF-16 offset into the source. |
Principal
Who an access token acts for.
| Field | Type | About |
|---|---|---|
apiKeyId | string | |
apiKeyName | string | |
displayName | string | Optional. |
userId | string |
QueryRejected
The query could not be run as written. Every diagnostic is something editing the source can fix.
| Field | Type | About |
|---|---|---|
diagnostics | Diagnostic[] |
QueryRequest
| Field | Type | About |
|---|---|---|
source | string | Query-language text, exactly as typed in the topspin editor. |
QueryResult
A query's answer.
| Field | Type | About |
|---|---|---|
columns | Column[] | |
datasetId | string | |
elapsedMs | number | |
highlights | HighlightRule[] | |
notes | string[] | Caveats about the answer: coverage, implied filters. |
orderedBy | OrderedBy | Optional. |
pairs | ColumnPair[] | |
pivot | Pivot | Optional. |
rowCount | integer | |
rows | Row[] | |
sources | Source[] | |
truncated | boolean | True when the row limit was reached and more rows exist. |
warnings | Diagnostic[] | Problems in the source the query ran despite — a line that could not be read is skipped, as the editor skips it. Empty when the source is clean. |
Range
A half-open range of the source text: end is the first position after it.
Row
| Field | Type | About |
|---|---|---|
cells | Cell[] | One per column, in column order. |
highlighted | boolean | True when the query's highlight rules point at this row. |
SortDirection
One of asc, desc.
Source
Who the numbers belong to.
| Field | Type | About |
|---|---|---|
id | string | |
label | string | |
url | string | Optional. |
TokenRequest
An API key, to trade for an access token.
| Field | Type | About |
|---|---|---|
clientId | string | The API key's client id, topspin-api-…. |
clientSecret | string | The secret shown once when the key was created. |
TokenResponse
A Keycloak access token for the topspin API.
| Field | Type | About |
|---|---|---|
accessToken | string | Send in the Authorization header with the Bearer scheme. |
expiresIn | integer | Seconds until the token expires. Fetch a new one rather than refreshing. |
tokenType | string |
ValidationResult
What checking a query without running it found.
| Field | Type | About |
|---|---|---|
diagnostics | Diagnostic[] | |
valid | boolean | True when the query would run: it parses and every name in it resolves. |