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.
Prerequisites
Section titled “Prerequisites”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
Langauge Models
Section titled “Langauge Models”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 modelGPT_4_TURBO
: OpenAI’s GPT-4 Turbo modelGPT_4O
: OpenAI’s GPT-4 Optimized modelGPT_4O_MINI
: OpenAI’s GPT-4 Optimized Mini modelO1
: FSCO’s O1 modelO1_MINI
: FSCO’s O1 Mini modelO3_MINI
: FSCO’s O3 Mini modelLLAMA_3
: Meta’s Llama 3 modelCLAUDE_OPUS
: Anthropic’s Claude Opus modelCLAUDE_SONNET
: Anthropic’s Claude Sonnet model
The model we recommend for most use cases is GPT_4O
.
Model List Endpoint
Section titled “Model List Endpoint”GET /v2/document/model
Get Model List
Section titled “Get Model List”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 usagegetModelList();
import osimport requests
api_key = os.getenv('FSCO_API_KEY')api_secret = os.getenv('FSCO_API_SECRET')def get_model_list(): url = 'https://api.fsco.io/v2/document/model' headers = { 'x-api-key': api_key, 'x-api-secret': api_secret, 'Content-Type': 'multipart/form-data' } params = { 'page': 1, 'limit': 10 }
try: response = requests.get(url, headers=headers, params=params) response.raise_for_status() print('Model list:', response.json()) except requests.exceptions.RequestException as e: print('Error getting model list:', e)
# Example usageget_model_list()
using System;using System.Net.Http;using System.Net.Http.Headers;using System.Threading.Tasks;
class TemplateLister{ static async Task Main() { var apiKey = Environment.GetEnvironmentVariable("FSCO_API_KEY"); var apiSecret = Environment.GetEnvironmentVariable("FSCO_API_SECRET");
var client = new HttpClient(); client.DefaultRequestHeaders.Add("x-api-key", apiKey); client.DefaultRequestHeaders.Add("x-api-secret", apiSecret); client.DefaultRequestHeaders.Add("Content-Type", "application/json");
var response = await client.GetAsync("https://api.fsco.io/v2/document/model?page[number]=1&limit=10"); var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine("Provider model list: " + responseString); }}
#!/bin/bash
curl -X GET "https://api.fsco.io/v2/document/model?page[number]=1&limit=10" \ -H "x-api-key: $FSCO_API_KEY" \ -H "x-api-secret: $FSCO_API_SECRET" \ -H "Content-Type: application/json"
Document Types
Section titled “Document Types”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 portal | API Value |
---|---|
Account Statement | account_statement |
Airway Bill | airway_bill |
Applications | applications |
Bill of Lading | bill_of_lading |
Business (general) | business_general |
Certificate of Origin | certificate_of_origin |
Contract | contract |
Financial | financial |
Health Certificate | health_certificate |
Identification | identification |
Insurance | insurance |
Invoice | invoice |
Other | other |
Purchase Order | purchase_order |
Receipt | receipt |
Report/Proposal | report_proposal |
Creating a Template
Section titled “Creating a Template”The request requires:
name
: The name for your templatedescription
: A description of the template’s purposetype
: The type of template (from the list of supported document types)tag
: A tag for categorizing the templateproviderModelId
: 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
Example Request
Section titled “Example Request”#!/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" } ] }'
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 createTemplate() { try { const response = await axios.post( `${baseURL}/templates`, { 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' } ] }, { headers: { 'x-api-key': apiKey, 'x-api-secret': apiSecret, 'Content-Type': 'application/json' } } ); console.log('Template created:', response.data); } catch (error) { console.error('Error creating template:', error); }}
// Example usagecreateTemplate();
import osimport requests
api_key = os.getenv('FSCO_API_KEY')api_secret = os.getenv('FSCO_API_SECRET')
def create_template(): url = 'https://api.fsco.io/v2/document/template' headers = { 'x-api-key': api_key, 'x-api-secret': api_secret, 'Content-Type': 'multipart/form-data' } data = { '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' } ] }
try: response = requests.post(url, headers=headers, json=data) response.raise_for_status() print('Template created:', response.json()) except requests.exceptions.RequestException as e: print('Error creating template:', e)
# Example usagecreate_template()
using System;using System.Net.Http;using System.Net.Http.Headers;using System.Text;using System.Text.Json;using System.Threading.Tasks;
class TemplateCreator{ static async Task Main() { var apiKey = Environment.GetEnvironmentVariable("FSCO_API_KEY"); var apiSecret = Environment.GetEnvironmentVariable("FSCO_API_SECRET");
var client = new HttpClient(); client.DefaultRequestHeaders.Add("x-api-key", apiKey); client.DefaultRequestHeaders.Add("x-api-secret", apiSecret); client.DefaultRequestHeaders.Add("Content-Type", "application/json");
var template = new { name = "Your Template Name", description = "Your Template Description", type = "document", tag = "document", providerModelId = "Your Provider Model Id", prompts = new[] { new { id = "Your Prompt Id", name = "Your Prompt Name", fieldType = "string", format = "string", description = "Your Prompt Description", itemType = "string" } } };
var content = new StringContent( JsonSerializer.Serialize(template), Encoding.UTF8, "application/json" );
var response = await client.PostAsync("https://api.fsco.io/v2/document/template", content); var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine("Template created: " + responseString); }}
Response
Section titled “Response”{ "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"}
Get Template List
Section titled “Get Template List”Listing templates enables organisational management of templates with access to editing features.
Endpoint
Section titled “Endpoint”GET /v2/document/template
Query Parameters
Section titled “Query Parameters”All parameters are required:
tag
: Tag to filter templates (string)skip
: Page number to skip to (number)limit
: Number of items per page (number)
Example Request
Section titled “Example Request”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 usagegetTemplateList();
import osimport requests
api_key = os.getenv('FSCO_API_KEY')api_secret = os.getenv('FSCO_API_SECRET')def get_template_list(): url = 'https://api.fsco.io/v2/document/template' headers = { 'x-api-key': api_key, 'x-api-secret': api_secret, 'Content-Type': 'multipart/form-data' } params = { 'page': 1, 'limit': 10 }
try: response = requests.get(url, headers=headers, params=params) response.raise_for_status() print('Template list:', response.json()) except requests.exceptions.RequestException as e: print('Error getting template list:', e)
# Example usageget_template_list()
using System;using System.Net.Http;using System.Net.Http.Headers;using System.Threading.Tasks;
class TemplateLister{ static async Task Main() { var apiKey = Environment.GetEnvironmentVariable("FSCO_API_KEY"); var apiSecret = Environment.GetEnvironmentVariable("FSCO_API_SECRET");
var client = new HttpClient(); client.DefaultRequestHeaders.Add("x-api-key", apiKey); client.DefaultRequestHeaders.Add("x-api-secret", apiSecret); client.DefaultRequestHeaders.Add("Content-Type", "application/json");
var response = await client.GetAsync("https://api.fsco.io/v2/document/template?page[number]=1&limit=10"); var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine("Template list: " + responseString); }}
#!/bin/bash
curl -X GET "https://api.fsco.io/v2/document/template?page[number]=1&limit=10" \ -H "x-api-key: $FSCO_API_KEY" \ -H "x-api-secret: $FSCO_API_SECRET" \ -H "Content-Type: application/json"
Response
Section titled “Response”{ "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}
Update a Template
Section titled “Update a Template”Endpoint
Section titled “Endpoint”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.
Example Request
Section titled “Example Request”#!/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" } ] }'
import axios from 'axios';
const apiKey = process.env.FSCO_API_KEY;const apiSecret = process.env.FSCO_API_SECRET;
async function updateTemplate() { const templateId = '8c1d496f-2827-4750-a11f-74b48c11108d'; const url = `https://api.fsco.io/v2/document/template/${templateId}`;
const headers = { 'x-api-key': apiKey, 'x-api-secret': apiSecret, 'Content-Type': 'application/json' };
const data = { 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' } ] };
try { const response = await axios.put(url, data, { headers }); console.log('Template updated:', response.data); } catch (error) { console.error('Error updating template:', error); }}
// Example usageupdateTemplate();
import osimport requests
api_key = os.getenv('FSCO_API_KEY')api_secret = os.getenv('FSCO_API_SECRET')
def update_template(): template_id = '8c1d496f-2827-4750-a11f-74b48c11108d' url = f'https://api.fsco.io/v2/document/template/{template_id}'
headers = { 'x-api-key': api_key, 'x-api-secret': api_secret, 'Content-Type': 'application/json' }
data = { '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' } ] }
try: response = requests.put(url, headers=headers, json=data) response.raise_for_status() print('Template updated:', response.json()) except requests.exceptions.RequestException as e: print('Error updating template:', e)
# Example usageupdate_template()
using System;using System.Net.Http;using System.Text;using System.Text.Json;using System.Threading.Tasks;
class TemplateUpdater{ static async Task Main() { var apiKey = Environment.GetEnvironmentVariable("FSCO_API_KEY"); var apiSecret = Environment.GetEnvironmentVariable("FSCO_API_SECRET"); var templateId = "8c1d496f-2827-4750-a11f-74b48c11108d";
var client = new HttpClient(); client.DefaultRequestHeaders.Add("x-api-key", apiKey); client.DefaultRequestHeaders.Add("x-api-secret", apiSecret); client.DefaultRequestHeaders.Add("Content-Type", "application/json");
var data = new { name = "Updated Template Name", description = "Updated Template Description", type = "document", tag = "document", providerModelId = "Your Provider Model Id", prompts = new[] { new { id = "Your Prompt Id", name = "Updated Prompt Name", fieldType = "string", format = "string", description = "Updated Prompt Description", itemType = "string" } } };
var content = new StringContent( JsonSerializer.Serialize(data), Encoding.UTF8, "application/json" );
var response = await client.PutAsync( $"https://api.fsco.io/v2/document/template/{templateId}", content );
var responseString = await response.Content.ReadAsStringAsync(); Console.WriteLine("Template updated: " + responseString); }}
Response
Section titled “Response”{ "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" } ]}
List Templates
Section titled “List Templates”Endpoint
Section titled “Endpoint”GET /v2/document/template
Query Parameters
Section titled “Query Parameters”All parameters are required:
tag
: Tag to filter templates (string)skip
: Page number to skip to (number)limit
: Number of items per page (number)
Example Request
Section titled “Example Request”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 usagegetTemplateList();
import osimport requests
api_key = os.getenv('FSCO_API_KEY')api_secret = os.getenv('FSCO_API_SECRET')def get_template_list(): url = 'https://api.fsco.io/v2/document/template' headers = { 'x-api-key': api_key, 'x-api-secret': api_secret, 'Content-Type': 'multipart/form-data' } params = { 'page': 1, 'limit': 10 }
try: response = requests.get(url, headers=headers, params=params) response.raise_for_status() print('Template list:', response.json()) except requests.exceptions.RequestException as e: print('Error getting template list:', e)
# Example usageget_template_list()
using System;using System.Net.Http;using System.Net.Http.Headers;using System.Threading.Tasks;
class TemplateLister{ static async Task Main() { var apiKey = Environment.GetEnvironmentVariable("FSCO_API_KEY"); var apiSecret = Environment.GetEnvironmentVariable("FSCO_API_SECRET");
var client = new HttpClient(); client.DefaultRequestHeaders.Add("x-api-key", apiKey); client.DefaultRequestHeaders.Add("x-api-secret", apiSecret); client.DefaultRequestHeaders.Add("Content-Type", "application/json");
var response = await client.GetAsync("https://api.fsco.io/v2/document/template?page[number]=1&limit=10"); var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine("Template list: " + responseString); }}
#!/bin/bash
curl -X GET "https://api.fsco.io/v2/document/template?page[number]=1&limit=10" \ -H "x-api-key: $FSCO_API_KEY" \ -H "x-api-secret: $FSCO_API_SECRET" \ -H "Content-Type: application/json"
Response
Section titled “Response”{ "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}
Get Template
Section titled “Get Template”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.
Endpoint
Section titled “Endpoint”GET /v2/document/template/{templateId}/version/{version}
Example Request
Section titled “Example Request”#!/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"
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 getTemplateByVersion() { try { const response = await axios.get( `${baseURL}/templates/8c1d496f-2827-4750-a11f-74b48c11108d/version/ffd93517-086f-4be9-891f-02b00453af58`, { headers: { 'x-api-key': apiKey, 'x-api-secret': apiSecret, 'Content-Type': 'application/json' } } ); console.log('Template version:', response.data); } catch (error) { console.error('Error getting template version:', error); }}
// Example usagegetTemplateByVersion();
import osimport requests
api_key = os.getenv('FSCO_API_KEY')api_secret = os.getenv('FSCO_API_SECRET')
def get_template_by_version(): template_id = '8c1d496f-2827-4750-a11f-74b48c11108d' version = 'ffd93517-086f-4be9-891f-02b00453af58' url = f'https://api.fsco.io/v2/document/template/{template_id}/version/{version}' headers = { 'x-api-key': api_key, 'x-api-secret': api_secret, 'Content-Type': 'multipart/form-data' }
try: response = requests.get(url, headers=headers) response.raise_for_status() print('Template version:', response.json()) except requests.exceptions.RequestException as e: print('Error getting template version:', e)
# Example usageget_template_by_version()
using System;using System.Net.Http;using System.Net.Http.Headers;using System.Threading.Tasks;
class TemplateVersionGetter{ static async Task Main() { var apiKey = Environment.GetEnvironmentVariable("FSCO_API_KEY"); var apiSecret = Environment.GetEnvironmentVariable("FSCO_API_SECRET");
var client = new HttpClient(); client.DefaultRequestHeaders.Add("x-api-key", apiKey); client.DefaultRequestHeaders.Add("x-api-secret", apiSecret); client.DefaultRequestHeaders.Add("Content-Type", "application/json");
var templateId = "8c1d496f-2827-4750-a11f-74b48c11108d"; var version = "ffd93517-086f-4be9-891f-02b00453af581";
var response = await client.GetAsync($"https://api.fsco.io/v2/document/template/{templateId}/version/{version}"); var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine("Template version: " + responseString); }}
Response
Section titled “Response”{ "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"}
Important Notes
Section titled “Important Notes”- 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