TypeScript SDK
@gemmai/sdk is the official client for TypeScript and JavaScript. It types the attributes of every model version, so your editor autocompletes them and catches mistakes before you send a request.
Install
npm install @gemmai/sdk
The SDK has no dependencies. It runs on Node.js 20+, Bun, Deno, and modern browsers. Only use it in a browser if you are fine with exposing your API key there.
Your first valuation
Create a client with your API key and call valuate():
import { GemmaiSDK } from '@gemmai/sdk'
const gemmai = new GemmaiSDK({ apiKey: process.env.GEMMAI_API_KEY! })
const result = await gemmai.valuate({
model: 'wristwatch@0.2',
attributes: {
brand: 'Rolex',
model: 'Submariner',
referenceNumber: '116610LN',
},
})
console.log(result.valuation.value) // 125000
console.log(result.valuation.currency) // "SEK"
console.log(result.model) // "wristwatch@0.2"
result has the same shape as the POST /v1/valuations response: valuation, attributes, enrichment, warnings and id.
Typed attributes
The value of model decides the type of attributes. Set model: 'car@0.1' and your editor suggests licensePlate, fuelType, gearbox and the other car fields. Enum fields only accept their allowed values, and descriptions and min/max limits show on hover.
await gemmai.valuate({
model: 'wristwatch@0.2',
attributes: {
brand: 'Rolex',
strap: 'gold',
// ~~~~~ Type '"gold"' is not assignable to type '"steel" | "leather" | ...'
},
})
Which attributes are required depends on the model and on whether enrichment runs:
| Case | attributes |
|---|---|
Models with enrichment (car, wristwatch) | Send what you know. The API fills in the rest before valuating, as in the first example above. |
The same models with options: { skipEnrich: true } | Every required attribute must be present. The compiler lists any that are missing. |
Models without enrichment (ring, necklace, property) | Every required attribute must be present. |
Any model with input: { text } | Send what you know. The API reads the rest from the text, as in From a description. |
The Attributes guide lists every attribute per model.
Model versions
Pass a pinned model id like wristwatch@0.2 and you get that exact schema, both in the API and in your types. A released version never changes.
Pass a bare asset type like wristwatch and the API runs its current default version. The SDK types it as the version that was the default when your SDK version was released. If the API later moves to a new default, your types can lag behind it. Pin versions in production code.
To see what the API serves right now:
const models = await gemmai.models.list()
// [{ name: 'car@0.1', assetType: 'car', deployedAt: '2026-03-25', isDefault: true }, ...]
const cars = await gemmai.models.list({ assetType: 'car' })
When a new model version ships, update @gemmai/sdk to get its types.
Model schemas
models.schema() returns everything about a model's attributes: the plain JSON Schema, a flat list of fields to build forms from, and a validator that runs locally.
const schema = await gemmai.models.schema('wristwatch@0.2')
schema.model // "wristwatch@0.2"
schema.jsonSchema // the plain JSON Schema
schema.fields // every attribute, in order
Fields
Each field has everything you need to render an input for it:
schema.field('strap')
// {
// name: 'strap',
// type: 'enum',
// required: true,
// description: 'The material of the strap',
// options: ['steel', 'leather', 'fabric', ...],
// }
schema.field('caseDiameter')
// { name: 'caseDiameter', type: 'number', required: true, min: 12, max: 60, ... }
schema.requiredFields
// ['brand', 'year', 'strap', 'bezel', 'case', ...]
- Name
name- Type
- string
- Description
The attribute name.
field()only accepts names that exist on the model.
- Name
type- Type
- string
- Description
One of
string,number,integer,boolean,enumorarray.
- Name
required- Type
- boolean
- Description
Whether the attribute must be present when enrichment is skipped.
- Name
options- Type
- string[]
- Description
The allowed values, for
enumfields and forarrayfields whose items come from a fixed list.
- Name
min, max- Type
- number
- Description
Inclusive bounds, for numbers.
- Name
minLength, maxLength- Type
- number
- Description
Length bounds, for strings.
- Name
reference- Type
- string
- Description
Set when you can look up known values with
reference.search(). Pass it asfield. Good for autocomplete onbrandandmodel.
- Name
schema- Type
- object
- Description
The field's own JSON Schema, for anything not covered above.
A simple form from the fields:
{schema.fields.map((field) =>
field.type === 'enum' ? (
<select key={field.name} name={field.name} required={field.required}>
{field.options!.map((o) => <option key={o}>{o}</option>)}
</select>
) : (
<input
key={field.name}
name={field.name}
type={field.type === 'string' ? 'text' : field.type === 'boolean' ? 'checkbox' : 'number'}
min={field.min}
max={field.max}
required={field.required}
/>
),
)}
Validate locally
validate() checks attributes against the schema without calling the API. It returns the same error codes as the API, so you can show errors next to each input before the user submits:
const result = schema.validate(formValues)
if (result.valid) {
result.attributes // typed as the wristwatch@0.2 attributes
} else {
result.errors
// [
// { field: 'year', code: 'missingField', message: 'Required' },
// { field: 'caseDiameter', code: 'valueTooHigh', message: 'Must be at most 60' },
// ]
}
While a form is still being filled in, or for input you will pass to enrich(), pass { partial: true } to check only the attributes that are present:
schema.validate({ brand: 'Rolex', caseDiameter: 80 }, { partial: true })
// errors: [{ field: 'caseDiameter', code: 'valueTooHigh', ... }]
Unknown attributes are ignored, as the API drops them.
| Code | Meaning |
|---|---|
missingField | A required attribute is missing. |
invalidType | Wrong type, e.g. a string where a number is expected. |
invalidValue | Not one of the allowed values. |
valueTooLow / valueTooHigh | A number is outside its min / max. |
tooShort / tooLong | A string is shorter or longer than allowed, e.g. empty. |
In the browser
Keep your API key on your server. Fetch the schema there, send its JSON to the browser, and rebuild it with ModelSchema.fromJSON(). The browser can then list fields and validate without a key:
// On your server
const schema = await gemmai.models.schema('wristwatch@0.2')
return Response.json(schema) // serialises with toJSON()
// In the browser
import { ModelSchema } from '@gemmai/sdk'
const json = await fetch('/api/watch-schema').then((r) => r.json())
const schema = ModelSchema.fromJSON<'wristwatch@0.2'>(json)
schema.validate(formValues)
Pinned schemas like wristwatch@0.2 never change, so the client caches them: calling models.schema() again for the same version doesn't send another request.
Enrich, then valuate
If you have a photo, or only a few details, analyse the image and enrich the attributes first. enrich() accepts partial attributes for any model:
const { fileId } = await gemmai.files.create({
imageUrl: 'https://example.com/watch.jpg',
})
const enriched = await gemmai.enrich({
model: 'wristwatch@0.2',
attributes: { brand: 'Rolex' },
input: { file: { fileId } },
})
const incomplete = enriched.warnings.find((w) => w.code === 'ATTRIBUTES_INCOMPLETE')
if (incomplete) {
// Ask the user for the missing fields, e.g. "missing caseDiameter, condition"
console.log(incomplete.message)
}
You can also skip the separate step: pass the file straight to valuate() and the API enriches before valuating.
await gemmai.valuate({
model: 'wristwatch@0.2',
attributes: { brand: 'Rolex' },
input: { file: { fileId } },
})
From a description
If the user describes the item in their own words, send the text in input.text. The API reads the model's attributes from it, then enriches and values as usual. attributes can be partial for every model:
const result = await gemmai.valuate({
model: 'ring@0.1',
attributes: {},
input: { text: 'Vitguldsring 18k med briljant, väger 3,1 g.' },
})
result.enrichment?.enriched.filter((e) => e.source === 'TEXT')
// [{ attribute: 'material', value: 'white gold', source: 'TEXT', confidence: 0.95 }, ...]
You can send text and file together. Attributes you send always win over what's read from input.
To have the API check attributes without running a valuation, use validate(). To check them without a request at all, use schema.validate().
const check = await gemmai.validate({ model: 'ring@0.1', attributes })
if (!check.valid) {
console.log(check.error) // [{ field: 'weight', code: 'missingField', message: '...' }]
}
See Enrich for how enrichment works.
Look up attribute values
Fields like brand and model are free text, but valuations are most accurate when the text matches the spelling in our data exactly. reference.search() returns the known values for a field, most common first. It works well for autocomplete:
const brands = await gemmai.reference.search({
field: 'brand',
q: 'rol',
where: { assetType: 'wristwatch' },
})
// [{ value: 'Rolex', probability: 0.97 }, ...]
const models = await gemmai.reference.search({
field: 'model',
q: 'sub',
where: { assetType: 'wristwatch', brand: 'Rolex' }, // only Rolex models
})
// [{ value: 'Submariner', probability: 0.82 }, ...]
Send the exact value back as the attribute.
where sets which items to search. It always needs an assetType, and it can include any attributes the user has already chosen to narrow the results. The asset type also decides which fields you can look up: brand, model or referenceNumber for wristwatch, and brand or model for car. Leave out q to get the most common values.
To list the asset types in the data, use reference.assetTypes().
Errors
Every failed call throws a GemmaiError. That covers responses with an error status, network failures and timeouts.
import { GemmaiError } from '@gemmai/sdk'
try {
await gemmai.valuate({ model: 'ring@0.1', attributes })
} catch (err) {
if (err instanceof GemmaiError) {
console.log(err.status) // 400
console.log(err.message) // "Invalid attributes: weight (...)"
console.log(err.details) // [{ field: 'weight', code: 'missingField', message: '...' }]
}
throw err
}
- Name
status- Type
- number
- Description
HTTP status of the response.
0when no response came back (network error, timeout or abort).
- Name
message- Type
- string
- Description
A readable description. For a 400 caused by invalid attributes, it names each attribute that failed.
- Name
details- Type
- ValidationIssue[]
- Description
One entry per invalid attribute, with
field,codeandmessage. Empty for other errors.
- Name
body- Type
- unknown
- Description
The parsed response body, if you need anything else from it.
See Error handling for what each status means.
Configuration
const gemmai = new GemmaiSDK({
apiKey: process.env.GEMMAI_API_KEY!,
baseUrl: 'https://api.gemmai.io', // default
timeout: 30_000, // milliseconds, default 30 seconds
fetch: customFetch, // optional, defaults to the global fetch
})
Every method takes an optional last argument to cancel the request or change its timeout:
const controller = new AbortController()
await gemmai.valuate(params, {
signal: controller.signal,
timeout: 10_000,
})
Method reference
| Method | Endpoint |
|---|---|
valuate({ model, attributes, input?, options? }) | POST /v1/valuations |
enrich({ model, attributes, input? }) | POST /v1/enrich |
validate({ model, attributes }) | POST /v1/validate |
models.list({ assetType? }) | GET /v1/models |
models.schema(model) → ModelSchema | GET /v1/models/{model}/schema |
files.create({ imageUrl }) | POST /v1/files |
reference.search({ field, q?, where: { assetType, ... } }) | GET /v1/reference/{field} |
reference.assetTypes({ q? }) | GET /v1/reference/assetType |
valuate() options are asOf (a Date, ISO string, YYYY-MM-DD or epoch seconds) and skipEnrich. See Valuation options.