Forms

Forms are useful in extracting structured information from documents or even guide conversations to fill a form.

Supports JSON Schema

To use forms in AI Library, you need to

  1. Create an agent with a form and provide a schema. The schema defines the structure of the form, including the fields and their types.
  2. To generate a structured response, use the chat endpoint with response_format set to json.
  3. To extract information from a conversation, use chat as is. Conversations will be guided to fill the form.

GEThttps://api.ailibrary.ai/v1/form

List Forms

List all forms.

Response

GET
/v1/form
{
    "forms": [
        {
            "created_timestamp": "2025-02-08 07:00:42",
            "title": "Test Form",
            "updated_timestamp": "2025-02-10 05:02:38",
            "userName": "John Doe",
            "form_id": "test_form"
        },
        /// ...
    ],
    "meta": {
        "current_page": 1,
        "limit": 50,
        "next_page": "",
        "prev_page": "",
        "total_items": 7,
        "total_pages": 1
    }
}

GEThttps://api.ailibrary.ai/v1/form/{form_id}

Retrieve Form

Get details of a specific form.

Path parameters

  • Name
    form_id
    Type
    string
    Required
    required
    Description

    Form ID.

Response

{
    "title": "Sample Form",
    "form_id": "sample_form",
    "schema": {
        "sample_string_field": {
            "order": 1,
            "type": "string",
            "description": "Tell me a joke"
        },
        "sample_boolean_field": {
            "order": 2,
            "type": "boolean",
            "description": "Do you like jokes?"
        },
        "sample_enum_field": {
            "order": 3,
            "type": "string",
            "description": "Pick your favorite joke category",
            "enum": [
                "",
                "Programming",
                "Miscellaneous",
                "Pun",
                "Spooky",
                "Christmas",
                "Science"
            ]
        }
    }
}

POSThttps://api.ailibrary.ai/v1/form

Create Form

Create a new form.

Request body

  • Name
    title
    Type
    string
    Required
    required
    Description

    Form title.

  • Name
    schema
    Type
    object
    Required
    required
    Description

    Form schema. The schema defines the structure of the form, including the fields and their types. Here's a sample object

    {
        "field_name": { 
            "type": "string", //can be string, number, boolean
            "order": 1, 
            "description": "What's your name?"  //This is the prompt for the agent
            "enum": ["", "option1", "option2"] //Optional. If the field is an enum, you can provide the options here
        },
        /// ...
    }
    

Request

POST
/v1/form
   curl --location 'https:/api.ailibrary.ai/v1/form' \
   --header 'Content-Type: application/json' \
   --header 'X-Library-Key: [[X-Library-Key-masked-secret]]' \
   --data '{
       "title": "Test Form",
       "schema": {
           "name": { "type": "string" },
           "email": { "type": "email" },
           "years_of_experience": { "type": "number" },
           "years_experience_with_nextjs": { "type": "number" },
           "AI_experience": { "type": "boolean" }
       }
   }'

Response

POST
/v1/form
{
    "form_id": "form_12345", //form_id
    "title": "...",
    "schema": "...",
}

PUThttps://api.ailibrary.ai/v1/form/{form_id}

Update Form

Update an existing form.

Request body

  • Name
    title
    Type
    string
    Required
    optional
    Description

    Form title.

  • Name
    schema
    Type
    object
    Required
    optional
    Description

    Form schema. The schema defines the structure of the form, including the fields and their types. Here's a sample object

    {
        "field_name": { 
            "type": "string", //can be string, number, boolean
            "order": 1, 
            "description": "What's your name?"  //This is the prompt for the agent
            "enum": ["", "option1", "option2"] //Optional. If the field is an enum, you can provide the options here
        },
        /// ...
    }
    

Request

PUT
/v1/form/{form_id}
curl --location --request PUT 'https://api.ailibrary.ai/v1/form/nextjs-dev_94745' \
--header 'Content-Type: application/json' \
--header 'X-Library-Key: [[X-Library-Key-masked-secret]]' \
--data '{
    "title": "Nextjs Developer",
    "schema": {
        "name": { "order": 1, "description": "What's the candidate's name?", "type": "string" },
        "email": { "order": 2, "description": "What's the candidate's email?", "type": "string" },
        "phone": { "order": 3, "description": "What's the candidate's phone number?", "type": "string" },
        "experience": { "order": 4, "description": "How many years of experience does the candidate have, overall?", "type": "number" },
        "AI_experience": { "order": 5, "description": "Does the candidate have experience with AI", "type": "boolean" },
        "AI_experience_details": { "order": 6, "description": "Explain the AI experience, only if the candidate has AI experience.", "type": "string" },
        "good_fit": { "order": 7, "description": "Is the candidate a good fit for the job?", "type": "boolean" }
    }
}'

Response

{
    "form_id": "form_12345", //form_id
    "title": "...",
    "schema": "...",
}

DELETEhttps://api.ailibrary.ai/v1/form/{form_id}

Delete Form

Delete a form by ID.

Path parameters

  • Name
    form_id
    Type
    string
    Required
    required
    Description

    Form ID.

Response

DELETE
/v1/form/{form_id}
curl --location --request DELETE 'https://api.ailibrary.ai/v1/form/test-form_45160' \
--header 'X-Library-Key: [[X-Library-Key-masked-secret]]'

Response

DELETE
/v1/form/{form_id}
{
    "status": "success",
    "message": "Form deleted successfully"
}

Was this page helpful?