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

  1. On topspin, open Settings → API keys → Create key. The secret is shown once. The key’s owner needs beta access.
  2. Trade the key for an access token. It lasts an hour; get a new one rather than refreshing it.
  3. 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

StatusBodyMeaning
200TokenResponseA Keycloak access token for the topspin API.
400ApiErrorThe request body does not match the schema. Never about the query text — see 422.
401ApiErrorNo access token, or one that was not accepted: expired, for another audience, or for a revoked key.
500ApiErrorSomething failed on topspin's side.
503ApiErrorThe authorization server or the database is not reachable.

GET /v1/me

Who the access token acts for.

Needs an access token.

StatusBodyMeaning
200PrincipalWho an access token acts for.
400ApiErrorThe request body does not match the schema. Never about the query text — see 422.
401ApiErrorNo access token, or one that was not accepted: expired, for another audience, or for a revoked key.
403ApiErrorThe API key's owner is not approved for the topspin beta.
500ApiErrorSomething failed on topspin's side.
503ApiErrorThe 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

StatusBodyMeaning
200QueryResultA query's answer.
400ApiErrorThe request body does not match the schema. Never about the query text — see 422.
401ApiErrorNo access token, or one that was not accepted: expired, for another audience, or for a revoked key.
403ApiErrorThe API key's owner is not approved for the topspin beta.
422QueryRejectedThe query cannot run as written. Every diagnostic is located in the source and fixable by editing it.
500ApiErrorSomething failed on topspin's side.
503ApiErrorThe 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

StatusBodyMeaning
200ValidationResultWhat checking a query without running it found.
400ApiErrorThe request body does not match the schema. Never about the query text — see 422.
401ApiErrorNo access token, or one that was not accepted: expired, for another audience, or for a revoked key.
403ApiErrorThe API key's owner is not approved for the topspin beta.
500ApiErrorSomething failed on topspin's side.
503ApiErrorThe 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.

FieldTypeAbout
codeApiErrorCode
messagestring

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.

FieldTypeAbout
booleanValuebooleanOptional.
kindCellKind
numberValuenumberOptional.
stringValuestringOptional.

CellKind

One of null, string, number, boolean.

Column

FieldTypeAbout
alignColumnAlign
caveatstringOptional.
descriptionstringOptional. The glossary's sentence for the stat.
formatColumnFormat
hintstringOptional. The sentence the query wrote for this heading with hint.
keystringThe column's name in the query language.
labelstring

ColumnAlign

One of left, right.

ColumnFormat

One of integer, decimal, decimal2, decimal3, percentage, percentage_whole, batting_avg, era, text.

ColumnPair

FieldTypeAbout
gueststring
hoststring

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.

FieldTypeAbout
codeDiagnosticCode
messagestring
rangeRangeOptional.
subjectstringOptional. 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

FieldTypeAbout
columnstring
operatorComparisonOperator
valueCell

HighlightRule

One highlight line. A row is highlighted when every condition of some rule holds.

FieldTypeAbout
conditionsHighlightCondition[]

OrderedBy

FieldTypeAbout
directionSortDirection
keystring

Pivot

How the answer was read as a matrix by pivot by.

FieldTypeAbout
bystring
headingsstring[]
labelstring

Position

FieldTypeAbout
columninteger1-based column, in UTF-16 code units.
lineinteger1-based line.
offsetinteger0-based UTF-16 offset into the source.

Principal

Who an access token acts for.

FieldTypeAbout
apiKeyIdstring
apiKeyNamestring
displayNamestringOptional.
userIdstring

QueryRejected

The query could not be run as written. Every diagnostic is something editing the source can fix.

FieldTypeAbout
diagnosticsDiagnostic[]

QueryRequest

FieldTypeAbout
sourcestringQuery-language text, exactly as typed in the topspin editor.

QueryResult

A query's answer.

FieldTypeAbout
columnsColumn[]
datasetIdstring
elapsedMsnumber
highlightsHighlightRule[]
notesstring[]Caveats about the answer: coverage, implied filters.
orderedByOrderedByOptional.
pairsColumnPair[]
pivotPivotOptional.
rowCountinteger
rowsRow[]
sourcesSource[]
truncatedbooleanTrue when the row limit was reached and more rows exist.
warningsDiagnostic[]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.

FieldTypeAbout
endPosition
startPosition

Row

FieldTypeAbout
cellsCell[]One per column, in column order.
highlightedbooleanTrue when the query's highlight rules point at this row.

SortDirection

One of asc, desc.

Source

Who the numbers belong to.

FieldTypeAbout
idstring
labelstring
urlstringOptional.

TokenRequest

An API key, to trade for an access token.

FieldTypeAbout
clientIdstringThe API key's client id, topspin-api-….
clientSecretstringThe secret shown once when the key was created.

TokenResponse

A Keycloak access token for the topspin API.

FieldTypeAbout
accessTokenstringSend in the Authorization header with the Bearer scheme.
expiresInintegerSeconds until the token expires. Fetch a new one rather than refreshing.
tokenTypestring

ValidationResult

What checking a query without running it found.

FieldTypeAbout
diagnosticsDiagnostic[]
validbooleanTrue when the query would run: it parses and every name in it resolves.