API

A GraphQL based API (Application Programming Interface) can be used to query the HLA Serotype Database.

How GraphQL APIs Work

Your App

GraphQL Query

GraphQL API

JSON Response

Serotype Data

An API (Application Programming Interface) defines a set of rules and protocols that enable different software applications to interact with one another. GraphQL is a query language designed for APIs that not only lets you retrieve data but also lets you specify exactly which data fields should be returned. This targeted approach ensures you obtain precisely the information you need in an efficient manner.

API Endpoint

https://www.serotype.org/api/graphql

Header (key:value)

x-api-key:

YOUR_API_KEY

Response size cap

Request limits

An account may make 600 requests a minute across its keys (up to 5 active keys). Over that, the API answers HTTP 429 with a Retry-After header.

A list argument takes up to 5,000 names; alleles with allele_exact_match: false takes up to 20 patterns. One operation may hold 10 root fields, 500 fields and 20 aliases, and a request body 256 kB. A request over a limit gets an error naming it.

An account may pull about 200 MB of data a day through the API (requests and responses together, reset at 00:00 UTC); past that the API answers 429 with the code DAILY_ALLOWANCE_EXCEEDED. For anything that large, use the downloads.

Fetching bulk data in R or curl

The getDownloads query returns a files array enumerating every pre-built file with its scope, locus, resolution, format, and a ready-to-use url. Export files are research use only: filenames carry a RESEARCH_USE_ONLY_ prefix and a random suffix and cannot be guessed — pick the row you want and fetch its url (don't build paths by hand). The same list is on the Downloads page.

# R — pull bulk full-field for the current version (research use only)
library(httr); library(jsonlite)
key <- Sys.getenv("SEROTYPE_API_KEY")
q <- 'query { getDownloads { version files { url scope resolution format } } }'
res <- POST("https://www.serotype.org/api/graphql",
            add_headers(.headers = c("x-api-key" = key)),
            body = list(query = q), encode = "json")
files <- fromJSON(content(res, "text", encoding = "UTF-8"))$data$getDownloads$files
row <- subset(files, scope == "bulk" & resolution == "full_field" & format == "json")
doc <- jsonlite::fromJSON(gzcon(url(row$url)))
df <- doc$data                     # rows; doc$metadata says which version and build
cat(doc$metadata$build_id, "rows:", nrow(df), "\n")
# curl — discover the file URL, then download it
URL=$(curl -s https://www.serotype.org/api/graphql \
  -H "x-api-key: $SEROTYPE_API_KEY" -H 'content-type: application/json' \
  -d '{"query":"{ getDownloads { files { url scope resolution format } } }"}' \
  | jq -r '.data.getDownloads.files[] | select(.scope=="bulk" and .resolution=="full_field" and .format=="json") | .url')
curl -sL "$URL" | gunzip -c | jq '.metadata.build_id, (.data | length)'

See lesson 3 for a walk-through of all three patterns for bulk data (query narrowing, cap-error handling, manifest-driven discovery).

Without limit and offset the whole result is returned, up to the 5000-row cap; above it a RESPONSE_TOO_LARGE error carries the matching download URL. With limit (1-5000) and/or offset you get exactly that page and never the error; alleleToSerotypeCount returns the total for the same filters. Null alleles (names ending in N) are not rows: HATS lists them with no protein and no antigen. A null allele named in alleles (exact match, no filter but loci) comes back as a row whose qualifier_code is NULL, so it is not mistaken for a name the release does not have.

Parameters

loci
[String!]
alleles
[String!]
allele_exact_match
Boolean
= true
hats_antigens
[String!]
hats_associated
[String!]
qualifiers
[String!]
hats_splits
[String!]
hats_broads
[String!]
bw4_bw6
[String!]
c1_c2
[String!]
dr5x
[String!]
ciwd
[String!]
cwd
[String!]
eurcwd
[String!]
who_status
[String!] (assigned | assigned_split | assigned_broad | conflict | mixed | assumed | unknown | null_allele | none)
ipd_hats_differs
Boolean (only alleles where the antigen IPD-IMGT/HLA's copy lists matches none of the allele's HATS rows)
ipd_hats_listed
Boolean (true: only alleles for which IPD-IMGT/HLA lists a HATS assignment; false: only those without one)
search
String (substring of allele, antigen, split, broad, qualifier or Bw4/Bw6)
protein_filters
[AminoAcidFilter!] { position, residue, residues (any of), is_definition }
resolution
Resolution
= two_field
accepts values: two_field or full_field
sort
AlleleSort
= allele
accepts values: allele or antigen
limit
Int (1-5000)
offset
Int

Response

locus
String
allele
String
qualifier
String
qualifier_code
String
qualifier_description
String
hats_antigen
String (the antigen HATS assigns the allele: its finest level, e.g. A2402, A25 or A1)
hats_level
AntigenLevel (broad | split | associated: which level hats_antigen is at; null when unassigned)
hats_associated
String (blank where the allele has no associated antigen, e.g. A*01:01, A*25:01)
hats_split
String (blank where the broad was never split, e.g. A*02:02)
hats_broad
String
ciwd
String
cwd
String
eurcwd
String
bw4_bw6
String
c1_c2
String
dr5x
String
who_antigen
String (WHO unambiguous antigen from IPD-IMGT/HLA rel_dna_ser.txt, named as the antigens here)
who_status
String (how the WHO antigen relates to the levels HATS gives the allele; see the Introduction page)
who_level
AntigenLevel (the level of the antigen WHO assigns; null when WHO assigns none of its own)
who_associated
String (WHO's levels, blank where none, e.g. A*02:06 is WHO A2 / - / -)
who_split
String
who_broad
String
who_possible
String (WHO possible antigens, slash-separated)
ipd_hats_antigen
String (the HATS assignment as listed by IPD-IMGT/HLA)
ipd_accession
String (IPD-IMGT/HLA accession, e.g. HLA00001; for a two-field name that is not itself an IPD allele, that of its lowest-numbered full-field allele)
ipd_accession_allele
String (the allele the accession belongs to)
protein
Protein
structure_model
StructureModel { allele, model_url, pae_url, chain_id, partner, partner_chain_id, sequence_status, observed_start, observed_end, filled_ranges { start, end }, donor_allele, same_model_as, mean_plddt_groove, mean_plddt_chain, ptm, iptm } (the allele's AlphaFold 3 model, a full-field allele's two-field group's; null for a null allele. AlphaFold 3 Output under the AlphaFold 3 Output Terms of Use: non-commercial use only, not for clinical use; cite Abramson et al., Nature 2024)
allele_url
String (the allele's page on the website, a stable link: https://www.serotype.org/allele/A*02:01)
antigen_url
String (its antigen's page; null when unassigned)
structure_url
String (the 3D structure viewer showing the allele: https://www.serotype.org/structure/allele/A*02:01)

Example Query

query {
  alleleToSerotype(
    alleles: ["A*02:01"]
    resolution: two_field
  ) {
    locus
    allele
    qualifier
    qualifier_code
    qualifier_description
    hats_antigen
    hats_level
    hats_associated
    hats_split
    hats_broad
    bw4_bw6
    c1_c2
    dr5x
    ciwd
    cwd
    eurcwd
    version
  }
}

Example Response

{
  "data": {
    "alleleToSerotype": [
      {
        "locus": "A",
        "allele": "A*02:01",
        "qualifier": "Full",
        "qualifier_code": "F",
        "qualifier_description": "Matches the antigen's reference pattern at every defining residue.",
        "hats_antigen": "A0201",
        "hats_level": "associated",
        "hats_associated": "A0201",
        "hats_split": "",
        "hats_broad": "A2",
        "bw4_bw6": "",
        "c1_c2": "",
        "dr5x": "",
        "ciwd": "C",
        "cwd": "C",
        "eurcwd": "C",
        "version": "1.0"
      }
    ]
  }
}

See the API in action using interactive tools that can generate the GraphQL query and return the results. Try it now

Learn how to use the API with interactive R examples at our learning portal