The CrystaLLM API

An API is available for programmatic access to CrystaLLM. The API is located at:

            https://api.crystallm.com/v1/generate
        

To use the service, an API key is required, which can be obtained by contacting us. Please note that there is a fee for using the API; see Pricing for more information. Alternatively, the model code and weights can be freely downloaded and used on personal hardware. The open source code repository contains instructions for setting up and using CrystaLLM.

Requests

To invoke CrystaLLM through the API, make a POST request, sending the API key in a header named x-api-key. Place the message payload in the body of the request.

For example, to request a structure for Ba2MnCr, with Z=3, in space group R3m:

            curl -X POST \
            -H "Content-Type: application/json" \
            -H "x-api-key: YOUR_API_KEY" \
            -d '{"model": "small", "message": {"comp": "Ba2MnCr", "z": 3, "sg": "R-3m"}}' \
            https://api.crystallm.com/v1/generate
        

In the example above, the body of the request contains the following properties:

As stated above, the sg property is optional. For example, to request a structure for Ba2MnCr with Z=3, and allow the space group to be determined during generation:

            curl -X POST \
            -H "Content-Type: application/json" \
            -H "x-api-key: YOUR_API_KEY" \
            -d '{"model": "small", "message": {"comp": "Ba2MnCr", "z": 3}}' \
            https://api.crystallm.com/v1/generate
        

Model Types

There are currently 3 kinds of models available: "small", "medium", and "large". The "small" model consists of ~25 million parameters. It has a request timeout of 60 seconds, and will generate a maximum of 1,200 tokens. It has difficulty generating valid CIFs that are longer than 500 tokens. However, it is the fastest of the models. The "medium" model consists of ~85 million parameters, and the "large" model consists of ~200 million parameters. These models have a request timeout of 120 seconds, and will generate a maximum of 2,000 tokens. These models are generally better than the "small" model, and can usually generate CIFs successfully that contain 1,000 or more tokens. However, these models are slower than the "small" model. Specify the model to be used in the model property of the payload.

Formation Energy

The formation energy per atom may be requested together with the generated structure. The formation energy per atom is predicted with ALIGNN. To include the ALIGNN-predicted formation energy per atom in the response, add the fe property with a value of true to the message payload. For example, to request a structure for NaCl, with Z=4, in space group Fm3m, together with its predicted formation energy per atom:

            curl -X POST \
            -H "Content-Type: application/json" \
            -H "x-api-key: YOUR_API_KEY" \
            -d '{"model":"small", "message":{"comp":"NaCl", "z":4, "sg":"Fm-3m"}, "fe":true}' \
            https://api.crystallm.com/v1/generate
        

Message Options

The message property of the payload contains the information that will be used to construct the prompt that will be given to the model. The comp property contains the composition of the formula unit. The z property contains the number of formula units in the unit cell. The sg property specifies the space group. The sg property is optional, whereas the comp and z properties are always required.

Valid values of Z

Any integer value > 0 is a valid value of z. However, note that the models generally perform best when z is one of 1, 2, 3, 4, 6, or 8.

Valid values of Space group

The following values for the sg property are supported:

P6/mmmImmaP4_32_12P4_2/mnm Fd-3mP3m1P-3P4mm
P4_332P4/nncP2_12_12Pnn2 PbcnP4_2/nCmR3m
CmceAea2P-42_1mP-42m P2_13R-3Fm-3Cmm2
Pn-3nP6/mccP3_2P-3m1 P3_212I23P-62mP4_2nm
Pma2PmmaI-42mP-31c Pa-3PmmnPmmmP4_2/ncm
I4/mcmI-4m2P3_1Pcc2 CmcmI222FdddP312
CccmP6_1F-43cP6_322 Pm-3P3_121P6_4Ia-3d
Pm-3mP2_1/cC222_1Pc P4/nPba2Ama2Pbcm
P31mPccaP222P-43n PccmP6_422F23P42_12
C222PnnnP6_3cmP4_12_12 P6/mFmm2I4_1/aP4/mbm
Pmn2_1P4_2bcP4_22_12I-43d I4/mP4bmFdd2P3
P6_122Pnc2P4_2/mcmP4_122 Cmc2_1P-6c2R32P4_1
P4_232PnnaP422Pban CcI4_122P6_3/mP6_3mc
I4_1/amdP4_2P4/nmmPmna P4/mFm-3mP4/mmmImm2
P4/nccP-62cIma2P6_5 P2/cP4/nbmIbamP6_522
P6_3/mmcI4/mmmFmmmP2/m P-4b2I-4C2/mP4_2/mmc
P4Fd-3cP4_3P2_1/m I-43mP-42cF4_132Pm
PccnP-4n2P4_132P23 I4cmR3cAmm2Immm
Iba2I4Fd-3P1 PbamP4_2/nbcIm-3P4_2/nnm
Pmc2_1P-31mR-3mIa-3 P622F222P2P-1
Pmm2P-4Aem2P6_222 P-3c1P4_322I422Pnma
P6_3P3c1Pn-3P4nc P-6P4/mccI2_12_12_1P4_2/mbc
P31cCcc2P4_2/nmcP6_3/mcm C2PbcaP-4c2I4_1cd
P2_1P3_112P4_2mcPn-3m C2/cR3P-43mI432
P222_1I-42dI-4c2P6cc P6_2P3_221P321Pca2_1
I4_1/acdI4_132F432Pna2_1 CcceIbcaP4/mncI4_1md
P2_12_12_1R-3cI2_13P-4m2 Pm-3nI4mmF-43mPnnm
P-42_1cCmmmP6mmP4_2cm P4_2/mIm-3mFm-3cI4_1
P4ccCmme

Responses

The response is a JSON object:

{
    "cifs": [
        {
            "input": {"comp": "Ba2Mn1Cr1", "sg": "R-3m", "z": 3},
            "generated": "data_Ba6Mn3Cr3\n_symmetry...",
            "valid": True,
            "messages": [None],
            "fe": 0.8906367421150208
        }
    ]
}
        

The response contains a single property, cifs, which is an array of generated CIFs. For now, the array will always contain a single item. The item contains the contents of the generated CIF in the generated property. The valid property states whether the generated CIF is valid, and the messages property contains a list of messages related to the generation (e.g. why the generation may have been considered invalid). Note that the fe property will only be present if the predicted formation energy per atom was requested.

If there was an error processing the request, the API will return either a 400 or 500 HTTP response status code, and the body of the response will look something like:

            {"error": "'model' property is missing"}
        

depending on the nature of the error.

Note that currently the API will take anywhere from several seconds to 1 or 2 minutes to respond to a single request (depending on the model type and the message options). Since the API is synchronous, clients should be prepared to wait a sufficient amount of time for a response.

Pricing *

* Prices are in USD. Fees apply to requests made on or after February 16 2024, and do not apply to API keys issued before this date.

Obtaining an API Key

If you are interested in accessing CrystaLLM through this API, please contact us for an API key.