Skip to content

Server SDK

Use @formtress/server in your server-side code to check submissions for spam before storing or acting on them. No data is saved — the filter endpoint only returns a spam score.

npm install @formtress/server

Current version: 0.1.0

Create a Formtress client with your API key, then call filter() on every submission:

import { Formtress } from '@formtress/server'
const formtress = new Formtress({
apiKey: process.env.FORMTRESS_API_KEY!, // starts with ftk_
})
const result = await formtress.filter({
ip: '1.2.3.4',
headers: Object.fromEntries(request.headers),
fields: [
{ name: 'email', value: 'test@gmail.com', type: 'email' },
{ name: 'message', value: 'Hello world', type: 'text' },
],
blockFreeEmailProviders: true,
})
if (result.isSpam) {
// reject the submission
}
  1. The submission arrives at your server with the end-user’s IP address and request headers.

  2. The SDK forwards the IP, headers, and field values to the Formtress filter endpoint.

  3. The API runs rate-limiting, bot detection, and content analysis. No field values are stored! The endpoint only returns a spam score.

  4. The API responds with { isSpam, score, fieldErrors }.

  5. Your server decides whether to accept the submission or reject it based on the result.

Create a client instance.

OptionTypeRequiredDescription
apiKeystringYesYour Formtress API key (ftk_…)

Check a submission for spam. Returns a FilterResult.

OptionTypeRequiredDefaultDescription
ipstringYesEnd-user’s IP address (used for rate limiting)
headersRecord<string,string>YesForwarded request headers from the end-user
fieldsFilterField[]NoField values for content-level spam detection
blockFreeEmailProvidersbooleanNofalseFlag free email providers (e.g. gmail.com)
interface FilterField {
name: string // field name, e.g. "email"
value: string // field value
type: string // field type, e.g. "email", "text", "url"
}
PropertyTypeDescription
isSpambooleanWhether the submission was detected as spam
scorenumberSpam confidence score (0–1)
rateLimitedbooleanWhether the end-user was rate limited
fieldErrorsRecord<string,string>?Per-field spam errors, keyed by field name

Thrown when the API returns a non-2xx response.

PropertyTypeDescription
messagestringError description
statusnumberHTTP status code
bodyunknownRaw response body
import { fail } from '@sveltejs/kit'
import { Formtress } from '@formtress/server'
import type { Actions } from './$types'
export const actions: Actions = {
default: async ({ request, getClientAddress }) => {
const formData = await request.formData()
const formtress = new Formtress({
apiKey: process.env.FORMTRESS_API_KEY!,
})
const result = await formtress.filter({
ip: getClientAddress(),
headers: Object.fromEntries(request.headers),
fields: [
{ name: 'email', value: formData.get('email') as string, type: 'email' },
{ name: 'message', value: formData.get('message') as string, type: 'text' },
],
blockFreeEmailProviders: true,
})
if (result.isSpam) {
return fail(403, { spam: true, result })
}
// save to DB, send email, etc.
return { success: true }
},
}

If you prefer to call the API directly without the SDK:

https://app.formtress.com/public/api/v1/filter

See the API Reference for the raw HTTP contract.