Skip to content

Templates

The Document AI service uses templates to extract data from documents.

Templates are reusable sets of prompts that define how data should be extracted and modeled from documents.

By creating a template, you establish a consistent structure for processing similar documents and extracting the same types of information each time.

This guide will walk you through the process of creating a template using our API and setting up the prompts needed to extract your desired data.

Creating a template is the first step to generating documents with FSCO.

Before you begin, ensure you have:

  • A valid FSCO API key
  • Your application’s environment configured with the API key
  • Some sample documents to guide your template creation

The document service uses language models to extract data from documents.

One of the required parameters for creating a template is the providerModelId. This is the ID of the model you want to use to extract data from your documents.

In order to use a model in your given environment, you’ll need to query the model list and set the providerModelId to the ID of the model you want to use.

The following language models are available for use:

  • GPT_4: OpenAI’s GPT-4 model
  • GPT_4_TURBO: OpenAI’s GPT-4 Turbo model
  • GPT_4O: OpenAI’s GPT-4 Optimized model
  • GPT_4O_MINI: OpenAI’s GPT-4 Optimized Mini model
  • O1: FSCO’s O1 model
  • O1_MINI: FSCO’s O1 Mini model
  • O3_MINI: FSCO’s O3 Mini model
  • LLAMA_3: Meta’s Llama 3 model
  • CLAUDE_OPUS: Anthropic’s Claude Opus model
  • CLAUDE_SONNET: Anthropic’s Claude Sonnet model

The model we recommend for most use cases is GPT_4O.

GET /v2/document/model
get-model-list.ts
import axios from 'axios';
const apiKey = process.env.FSCO_API_KEY;
const apiSecret = process.env.FSCO_API_SECRET;
const baseURL = 'https://api.fsco.com/v2';
async function getModelList() {
try {
const response = await axios.get(
`${baseURL}/document/model`,
{
params: {
page: 1,
limit: 10
},
headers: {
'x-api-key': apiKey,
'x-api-secret': apiSecret,
'Content-Type': 'application/json'
}
}
);
console.log('Model list:', response.data);
} catch (error) {
console.error('Error getting model list:', error);
}
}
// Example usage
getModelList();

Providing a template with a document type will help the AI model understand the context of the document and extract the data more accurately.

Choose the document type that best describes the type of document you are processing. The following document types are supported in the developer portal:

UI Label in developer portalAPI Value
Account Statementaccount_statement
Airway Billairway_bill
Applicationsapplications
Bill of Ladingbill_of_lading
Business (general)business_general
Certificate of Origincertificate_of_origin
Contractcontract
Financialfinancial
Health Certificatehealth_certificate
Identificationidentification
Insuranceinsurance
Invoiceinvoice
Otherother
Purchase Orderpurchase_order
Receiptreceipt
Report/Proposalreport_proposal

The request requires:

  • name: The name for your template
  • description: A description of the template’s purpose
  • type: The type of template (from the list of supported document types)
  • tag: A tag for categorizing the template
  • providerModelId: The ID of the AI model to use (from the supported language model query result)
  • prompts: An array of fields to extract from documents

Templates can also be created and tested using the developer portal which we recommend for quickly testing and iterating on your prompts in real time with a visual interface and your own documents.

POST /v2/document/template
create-template.sh
#!/bin/bash
curl -X POST "https://api.fsco.io/v2/document/template" \
-H "x-api-key: $FSCO_API_KEY" \
-H "x-api-secret: $FSCO_API_SECRET" \
-H "Content-Type: application/json" \
-d '{
"name": "Your Template Name",
"description": "Your Template Description",
"type": "document",
"tag": "document",
"providerModelId": "Your Provider Model Id",
"prompts": [
{
"id": "Your Prompt Id",
"name": "Your Prompt Name",
"fieldType": "string",
"format": "string",
"description": "Your Prompt Description",
"itemType": "string"
}
]
}'
response.json
{
"templateId": "8c1d496f-2827-4750-a11f-74b48c11108d",
"name": "Your Template Name",
"description": "Your Template Description",
"type": "document",
"tag": "document",
"providerModelId": "Your Provider Model Id",
"prompts": [
{
"id": "Your Prompt Id",
"name": "Your Prompt Name",
"fieldType": "string",
"format": "string",
"description": "Your Prompt Description",
"itemType": "string"
}
],
"createdAt": "2024-03-20T10:00:00Z",
"updatedAt": "2024-03-20T10:00:00Z"
}

Listing templates enables organisational management of templates with access to editing features.

GET /v2/document/template

All parameters are required:

  • tag: Tag to filter templates (string)
  • skip: Page number to skip to (number)
  • limit: Number of items per page (number)
get-template-list.ts
import axios from 'axios';
const apiKey = process.env.FSCO_API_KEY;
const apiSecret = process.env.FSCO_API_SECRET;
const baseURL = 'https://api.fsco.com/v2';
async function getTemplateList() {
try {
const response = await axios.get(
`${baseURL}/templates`,
{
params: {
page: 1,
limit: 10
},
headers: {
'x-api-key': apiKey,
'x-api-secret': apiSecret,
'Content-Type': 'application/json'
}
}
);
console.log('Template list:', response.data);
} catch (error) {
console.error('Error getting template list:', error);
}
}
// Example usage
getTemplateList();
response.json
{
"items": [
{
"templateId": "8c1d496f-2827-4750-a11f-74b48c11108d",
"name": "Your Template Name",
"description": "Your Template Description",
"type": "document",
"tag": "document",
"providerModelId": "Your Provider Model Id",
"prompts": [
{
"id": "Your Prompt Id",
"name": "Your Prompt Name",
"fieldType": "string",
"format": "string",
"description": "Your Prompt Description",
"itemType": "string"
}
],
"createdAt": "2024-03-20T10:00:00Z",
"updatedAt": "2024-03-20T10:00:00Z"
}
],
"total": 1,
"page": 1,
"limit": 10
}
PUT /v2/document/template/{templateId}

The request requires the same parameters as creating a template. When updating a template, a new version is automatically created.

update-template.sh
#!/bin/bash
curl -X PUT "https://api.fsco.io/v2/document/template/8c1d496f-2827-4750-a11f-74b48c11108d" \
-H "x-api-key: $FSCO_API_KEY" \
-H "x-api-secret: $FSCO_API_SECRET" \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Template Name",
"description": "Updated Template Description",
"type": "document",
"tag": "document",
"providerModelId": "Your Provider Model Id",
"prompts": [
{
"id": "Your Prompt Id",
"name": "Updated Prompt Name",
"fieldType": "string",
"format": "string",
"description": "Updated Prompt Description",
"itemType": "string"
}
]
}'
response.json
{
"templateId": "8c1d496f-2827-4750-a11f-74b48c11108d",
"name": "Updated Template Name",
"description": "Updated Template Description",
"type": "document",
"tag": "document",
"providerModelId": "Your Provider Model Id",
"version": "1.0.0",
"createdAt": "2024-03-20T10:00:00Z",
"updatedAt": "2024-03-20T11:00:00Z",
"prompts": [
{
"id": "Your Prompt Id",
"name": "Updated Prompt Name",
"fieldType": "string",
"format": "string",
"description": "Updated Prompt Description",
"itemType": "string"
}
]
}
GET /v2/document/template

All parameters are required:

  • tag: Tag to filter templates (string)
  • skip: Page number to skip to (number)
  • limit: Number of items per page (number)
get-template-list.ts
import axios from 'axios';
const apiKey = process.env.FSCO_API_KEY;
const apiSecret = process.env.FSCO_API_SECRET;
const baseURL = 'https://api.fsco.com/v2';
async function getTemplateList() {
try {
const response = await axios.get(
`${baseURL}/templates`,
{
params: {
page: 1,
limit: 10
},
headers: {
'x-api-key': apiKey,
'x-api-secret': apiSecret,
'Content-Type': 'application/json'
}
}
);
console.log('Template list:', response.data);
} catch (error) {
console.error('Error getting template list:', error);
}
}
// Example usage
getTemplateList();
response.json
{
"items": [
{
"templateId": "8c1d496f-2827-4750-a11f-74b48c11108d",
"name": "Your Template Name",
"description": "Your Template Description",
"type": "document",
"tag": "document",
"providerModelId": "Your Provider Model Id",
"prompts": [
{
"id": "Your Prompt Id",
"name": "Your Prompt Name",
"fieldType": "string",
"format": "string",
"description": "Your Prompt Description",
"itemType": "string"
}
],
"createdAt": "2024-03-20T10:00:00Z",
"updatedAt": "2024-03-20T10:00:00Z"
}
],
"total": 1,
"page": 1,
"limit": 10
}

To get a template, call the following endpoint with the template ID.

Section titled “To get a template, call the following endpoint with the template ID.”
GET /v2/document/template/{templateId}

This will return the template with the given ID and the latest version.

Every time a template is updated, a new version is created.

You can get a specific version of a template by providing the template ID and the version Id.

GET /v2/document/template/{templateId}/version/{version}
get-template-by-version.sh
#!/bin/bash
curl -X GET "https://api.fsco.io/v2/document/template/8c1d496f-2827-4750-a11f-74b48c11108d/version/ffd93517-086f-4be9-891f-02b00453af58" \
-H "x-api-key: $FSCO_API_KEY" \
-H "x-api-secret: $FSCO_API_SECRET" \
-H "Content-Type: application/json"
response.json
{
"templateId": "8c1d496f-2827-4750-a11f-74b48c11108d",
"version": 1,
"name": "Your Template Name",
"description": "Your Template Description",
"type": "document",
"tag": "document",
"providerModelId": "Your Provider Model Id",
"prompts": [
{
"id": "Your Prompt Id",
"name": "Your Prompt Name",
"fieldType": "string",
"format": "string",
"description": "Your Prompt Description",
"itemType": "string"
}
],
"createdAt": "2024-03-20T10:00:00Z",
"updatedAt": "2024-03-20T10:00:00Z"
}
  • Each template update creates a new version
  • Templates are versioned to maintain backward compatibility
  • The provider model ID must be valid and active
  • Prompts define the fields that will be extracted from documents
  • Template versions cannot be deleted once created