Interfaze

logo

Beta

pricing

docs

blog

sign in

Get Started

Introduction

Examples

Vision

Concepts

Resources

Projects

Integrations

Precontext

copy markdown

Interfaze is a hybrid model architecture that combines multiple specialized smaller models adapted to work together as a single LLM.

These specialized layers generate additional high quality structured metadata like confidence scores, bounding boxes, etc. that can be accessed through the precontext field.

This allows you to build reliable applications with predictable and structured metadata you can use to validate the confidence and accuracy of the model's responses.

When is precontext available?

precontext is only available for prompts that requires the model to perform one of the following tasks:

  • Vision (OCR, Object Detection)
  • Audio (Speech-to-Text)
  • Web (Web Search, Scraping)
  • Translation
  • Code (Code Sandboxing)
  • Guardrails

Use can also use run tasks allows you to programmatically run parts of the model without activating the full model and getting the raw metadata as the full response making it faster and cheaper.

Response types

  • Non-streaming responses: Returns precontext by default
  • Streaming responses: Doesn't return precontext by default (can be enabled by including the x-show-additional-info header)

Limits

Some SDKs don't provide a way to access the raw API response, so precontext is not available for those SDKs.

  • LangChain SDK does not provide an official way to access raw API responses, so field natively is not available.

Precontext structure

Within the body of the chat completion response, precontext is an array of objects. Each item has a name stating the specific task that was performed and the result field containing the raw metadata for that task.

{
  "object": {
    "first_name": "IVÁN",
    "last_name": "MUÑOZ ESTRADA",
    "dob": "09/12/1987",
    "driver_licence_number": "Y4067081"
  },
  "response": {
    "id": "interfaze-1774997933544",
    "modelId": "interfaze-beta",
    "body": {
      "id": "interfaze-1774997933544",
      "object": "chat.completion",
      "created": 1774997933,
      "model": "interfaze-beta",
      "usage": {
        "prompt_tokens": 16771,
        "completion_tokens": 2530,
        "total_tokens": 19301
      },
      "precontext": [
        {
          "name": "ocr",
          "result": {
            "extracted_text": "California\nUSA\nDRIVER LICENSE\nDL Y4067081\nCLASS C\nEXP 09/12/2027\nEND NONE\nEN MUÑOZ ESTRADA\nFN IVÁN ICHET\n14223 BELGATE ST\nBALDWIN PARK CA 91706\nDOB 09/12/1987\nRSTRNONE 09121987\nIvan M.\nSEX M HAIR BLK EYES BLK\nHGT 5-02\" WGT 185lb ISS\nDD 08/13/202160648/AAFD/27 07/25/2022",
            "sections": [
              {
                "text": "California\nUSA\nDRIVER LICENSE\nDL Y4067081\nCLASS C\nEXP 09/12/2027\nEND NONE\nEN MUÑOZ ESTRADA\nFN IVÁN ICHET\n14223 BELGATE ST\nBALDWIN PARK CA 91706\nDOB 09/12/1987\nRSTRNONE 09121987\nIvan M.\nSEX M HAIR BLK EYES BLK\nHGT 5-02\" WGT 185lb ISS\nDD 08/13/202160648/AAFD/27 07/25/2022",
                "lines": [
                  {
                    "text": "California",
                    "bounds": {
                      "top_left": {
                        "x": 63,
                        "y": 89
                      },
                      "top_right": {
                        "x": 268,
                        "y": 89
                      },
                      "bottom_right": {
                        "x": 268,
                        "y": 129
                      },
                      "bottom_left": {
                        "x": 63,
                        "y": 129
                      },
                      "width": 205,
                      "height": 40
                    },
                    "average_confidence": 0.99,
                    "words": [
                      {
                        "text": "California",
                        "bounds": {
                          "top_left": {
                            "x": 64,
                            "y": 90
                          },
                          "top_right": {
                            "x": 267,
                            "y": 89
                          },
                          "bottom_right": {
                            "x": 267,
                            "y": 130
                          },
                          "bottom_left": {
                            "x": 63,
                            "y": 130
                          },
                          "width": 203.5,
                          "height": 40.5
                        },
                        "confidence": 0.99
                      }
                    ]
                  },
                  {
                    "text": "USA",
                    "bounds": {
                      "top_left": {
                        "x": 270,
                        "y": 100
                      },
                      "top_right": {
                        "x": 296,
                        "y": 99
                      },
                      "bottom_right": {
                        "x": 296,
                        "y": 114
                      },
                      "bottom_left": {
                        "x": 269,
                        "y": 115
                      },
                      "width": 26.5,
                      "height": 15
                    },
                    "average_confidence": 0.96,
                    "words": [
                      {
                        "text": "USA",
                        "bounds": {
                          "top_left": {
                            "x": 269,
                            "y": 100
                          },
                          "top_right": {
                            "x": 294,
                            "y": 99
                          },
                          "bottom_right": {
                            "x": 295,
                            "y": 114
                          },
                          "bottom_left": {
                            "x": 269,
                            "y": 115
                          },
                          "width": 25.5,
                          "height": 15
                        },
                        "confidence": 0.96
                      }
                    ]
                  },
                  {
                    "text": "DRIVER LICENSE",
                    "bounds": {
                      "top_left": {
                        "x": 334,
                        "y": 91
                      },
                      "top_right": {
                        "x": 497,
                        "y": 91
                      },
                      "bottom_right": {
                        "x": 497,
                        "y": 113
                      },
                      "bottom_left": {
                        "x": 334,
                        "y": 114
                      },
                      "width": 163,
                      "height": 22.5
                    },
                    "average_confidence": 0.99,
                    "words": [
                      {
                        "text": "DRIVER",
                        "bounds": {
                          "top_left": {
                            "x": 335,
                            "y": 91
                          },
                          "top_right": {
                            "x": 405,
                            "y": 92
                          },
                          "bottom_right": {
                            "x": 405,
                            "y": 114
                          },
                          "bottom_left": {
                            "x": 335,
                            "y": 115
                          },
                          "width": 70,
                          "height": 23
                        },
                        "confidence": 0.99
                      },
                      {
                        "text": "LICENSE",
                        "bounds": {
                          "top_left": {
                            "x": 412,
                            "y": 92
                          },
                          "top_right": {
                            "x": 494,
                            "y": 91
                          },
                          "bottom_right": {
                            "x": 494,
                            "y": 113
                          },
                          "bottom_left": {
                            "x": 412,
                            "y": 114
                          },
                          "width": 82,
                          "height": 22
                        },
                        "confidence": 0.99
                      }
                    ]
                  },
                  {
                    "text": "DL Y4067081",
                    "bounds": {
                      "top_left": {
                        "x": 247,
                        "y": 153
                      },
                      "top_right": {
                        "x": 394,
                        "y": 153
                      },
                      "bottom_right": {
                        "x": 394,
                        "y": 178
                      },
                      "bottom_left": {
                        "x": 247,
                        "y": 179
                      },
                      "width": 147,
                      "height": 25.5
                    },
                    "average_confidence": 0.93,
                    "words": [
                      {
                        "text": "DL",
                        "bounds": {
                          "top_left": {
                            "x": 247,
                            "y": 154
                          },
                          "top_right": {
                            "x": 267,
                            "y": 154
                          },
                          "bottom_right": {
                            "x": 267,
                            "y": 179
                          },
                          "bottom_left": {
                            "x": 247,
                            "y": 179
                          },
                          "width": 20,
                          "height": 25
                        },
                        "confidence": 0.92
                      },
                      {
                        "text": "Y4067081",
                        "bounds": {
                          "top_left": {
                            "x": 272,
                            "y": 154
                          },
                          "top_right": {
                            "x": 393,
                            "y": 154
                          },
                          "bottom_right": {
                            "x": 393,
                            "y": 179
                          },
                          "bottom_left": {
                            "x": 272,
                            "y": 179
                          },
                          "width": 121,
                          "height": 25
                        },
                        "confidence": 0.95
                      }
                    ]
                  },
                  {
                    "text": "CLASS C",
                    "bounds": {
                      "top_left": {
                        "x": 453,
                        "y": 153
                      },
                      "top_right": {
                        "x": 521,
                        "y": 153
                      },
                      "bottom_right": {
                        "x": 521,
                        "y": 168
                      },
                      "bottom_left": {
                        "x": 453,
                        "y": 169
                      },
                      "width": 68,
                      "height": 15.5
                    },
                    "average_confidence": 0.99,
                    "words": [
                      {
                        "text": "CLASS",
                        "bounds": {
                          "top_left": {
                            "x": 454,
                            "y": 153
                          },
                          "top_right": {
                            "x": 503,
                            "y": 153
                          },
                          "bottom_right": {
                            "x": 503,
                            "y": 169
                          },
                          "bottom_left": {
                            "x": 455,
                            "y": 169
                          },
                          "width": 48.5,
                          "height": 16
                        },
                        "confidence": 0.99
                      },
                      {
                        "text": "C",
                        "bounds": {
                          "top_left": {
                            "x": 510,
                            "y": 154
                          },
                          "top_right": {
                            "x": 518,
                            "y": 154
                          },
                          "bottom_right": {
                            "x": 518,
                            "y": 168
                          },
                          "bottom_left": {
                            "x": 510,
                            "y": 169
                          },
                          "width": 8,
                          "height": 14.5
                        },
                        "confidence": 0.99
                      }
                    ]
                  },
                  {
                    "text": "EXP 09/12/2027",
                    "bounds": {
                      "top_left": {
                        "x": 244,
                        "y": 184
                      },
                      "top_right": {
                        "x": 397,
                        "y": 184
                      },
                      "bottom_right": {
                        "x": 397,
                        "y": 207
                      },
                      "bottom_left": {
                        "x": 244,
                        "y": 208
                      },
                      "width": 153,
                      "height": 23.5
                    },
                    "average_confidence": 0.96,
                    "words": [
                      {
                        "text": "EXP",
                        "bounds": {
                          "top_left": {
                            "x": 249,
                            "y": 185
                          },
                          "top_right": {
                            "x": 278,
                            "y": 185
                          },
                          "bottom_right": {
                            "x": 277,
                            "y": 209
                          },
                          "bottom_left": {
                            "x": 248,
                            "y": 208
                          },
                          "width": 29,
                          "height": 23.5
                        },
                        "confidence": 0.97
                      },
                      {
                        "text": "09/12/2027",
                        "bounds": {
                          "top_left": {
                            "x": 283,
                            "y": 185
                          },
                          "top_right": {
                            "x": 397,
                            "y": 184
                          },
                          "bottom_right": {
                            "x": 397,
                            "y": 208
                          },
                          "bottom_left": {
                            "x": 282,
                            "y": 209
                          },
                          "width": 114.5,
                          "height": 24
                        },
                        "confidence": 0.94
                      }
                    ]
                  },
                  {
                    "text": "END NONE",
                    "bounds": {
                      "top_left": {
                        "x": 454,
                        "y": 191
                      },
                      "top_right": {
                        "x": 536,
                        "y": 191
                      },
                      "bottom_right": {
                        "x": 536,
                        "y": 206
                      },
                      "bottom_left": {
                        "x": 454,
                        "y": 206
                      },
                      "width": 82,
                      "height": 15
                    },
                    "average_confidence": 0.99,
                    "words": [
                      {
                        "text": "END",
                        "bounds": {
                          "top_left": {
                            "x": 456,
                            "y": 192
                          },
                          "top_right": {
                            "x": 484,
                            "y": 192
                          },
                          "bottom_right": {
                            "x": 484,
                            "y": 206
                          },
                          "bottom_left": {
                            "x": 456,
                            "y": 206
                          },
                          "width": 28,
                          "height": 14
                        },
                        "confidence": 0.99
                      },
                      {
                        "text": "NONE",
                        "bounds": {
                          "top_left": {
                            "x": 493,
                            "y": 192
                          },
                          "top_right": {
                            "x": 533,
                            "y": 192
                          },
                          "bottom_right": {
                            "x": 533,
                            "y": 207
                          },
                          "bottom_left": {
                            "x": 492,
                            "y": 207
                          },
                          "width": 40.5,
                          "height": 15
                        },
                        "confidence": 0.99
                      }
                    ]
                  },
                  {
                    "text": "EN MUÑOZ ESTRADA",
                    "bounds": {
                      "top_left": {
                        "x": 248,
                        "y": 213
                      },
                      "top_right": {
                        "x": 449,
                        "y": 211
                      },
                      "bottom_right": {
                        "x": 449,
                        "y": 232
                      },
                      "bottom_left": {
                        "x": 248,
                        "y": 234
                      },
                      "width": 201,
                      "height": 21
                    },
                    "average_confidence": 0.73,
                    "words": [
                      {
                        "text": "EN",
                        "bounds": {
                          "top_left": {
                            "x": 249,
                            "y": 214
                          },
                          "top_right": {
                            "x": 269,
                            "y": 213
                          },
                          "bottom_right": {
                            "x": 269,
                            "y": 234
                          },
                          "bottom_left": {
                            "x": 249,
                            "y": 234
                          },
                          "width": 20,
                          "height": 20.5
                        },
                        "confidence": 0.31
                      },
                      {
                        "text": "MUÑOZ",
                        "bounds": {
                          "top_left": {
                            "x": 274,
                            "y": 213
                          },
                          "top_right": {
                            "x": 347,
                            "y": 212
                          },
                          "bottom_right": {
                            "x": 347,
                            "y": 234
                          },
                          "bottom_left": {
                            "x": 274,
                            "y": 234
                          },
                          "width": 73,
                          "height": 21.5
                        },
                        "confidence": 0.95
                      },
                      {
                        "text": "ESTRADA",
                        "bounds": {
                          "top_left": {
                            "x": 353,
                            "y": 212
                          },
                          "top_right": {
                            "x": 444,
                            "y": 212
                          },
                          "bottom_right": {
                            "x": 444,
                            "y": 233
                          },
                          "bottom_left": {
                            "x": 353,
                            "y": 234
                          },
                          "width": 91,
                          "height": 21.5
                        },
                        "confidence": 0.92
                      }
                    ]
                  },
                  {
                    "text": "FN IVÁN ICHET",
                    "bounds": {
                      "top_left": {
                        "x": 250,
                        "y": 233
                      },
                      "top_right": {
                        "x": 389,
                        "y": 233
                      },
                      "bottom_right": {
                        "x": 389,
                        "y": 253
                      },
                      "bottom_left": {
                        "x": 250,
                        "y": 254
                      },
                      "width": 139,
                      "height": 20.5
                    },
                    "average_confidence": 0.85,
                    "words": [
                      {
                        "text": "FN",
                        "bounds": {
                          "top_left": {
                            "x": 250,
                            "y": 234
                          },
                          "top_right": {
                            "x": 270,
                            "y": 234
                          },
                          "bottom_right": {
                            "x": 270,
                            "y": 254
                          },
                          "bottom_left": {
                            "x": 250,
                            "y": 255
                          },
                          "width": 20,
                          "height": 20.5
                        },
                        "confidence": 0.86
                      },
                      {
                        "text": "IVÁN",
                        "bounds": {
                          "top_left": {
                            "x": 274,
                            "y": 234
                          },
                          "top_right": {
                            "x": 318,
                            "y": 234
                          },
                          "bottom_right": {
                            "x": 317,
                            "y": 254
                          },
                          "bottom_left": {
                            "x": 274,
                            "y": 254
                          },
                          "width": 43.5,
                          "height": 20
                        },
                        "confidence": 0.7
                      },
                      {
                        "text": "ICHET",
                        "bounds": {
                          "top_left": {
                            "x": 327,
                            "y": 234
                          },
                          "top_right": {
                            "x": 387,
                            "y": 233
                          },
                          "bottom_right": {
                            "x": 386,
                            "y": 254
                          },
                          "bottom_left": {
                            "x": 327,
                            "y": 254
                          },
                          "width": 59.5,
                          "height": 20.5
                        },
                        "confidence": 0.99
                      }
                    ]
                  },
                  {
                    "text": "14223 BELGATE ST",
                    "bounds": {
                      "top_left": {
                        "x": 250,
                        "y": 255
                      },
                      "top_right": {
                        "x": 393,
                        "y": 253
                      },
                      "bottom_right": {
                        "x": 393,
                        "y": 271
                      },
                      "bottom_left": {
                        "x": 251,
                        "y": 272
                      },
                      "width": 142.5,
                      "height": 17.5
                    },
                    "average_confidence": 0.99,
                    "words": [
                      {
                        "text": "14223",
                        "bounds": {
                          "top_left": {
                            "x": 252,
                            "y": 256
                          },
                          "top_right": {
                            "x": 293,
                            "y": 256
                          },
                          "bottom_right": {
                            "x": 293,
                            "y": 272
                          },
                          "bottom_left": {
                            "x": 252,
                            "y": 272
                          },
                          "width": 41,
                          "height": 16
                        },
                        "confidence": 1
                      },
                      {
                        "text": "BELGATE",
                        "bounds": {
                          "top_left": {
                            "x": 296,
                            "y": 256
                          },
                          "top_right": {
                            "x": 366,
                            "y": 255
                          },
                          "bottom_right": {
                            "x": 366,
                            "y": 271
                          },
                          "bottom_left": {
                            "x": 297,
                            "y": 272
                          },
                          "width": 69.5,
                          "height": 16
                        },
                        "confidence": 0.99
                      },
                      {
                        "text": "ST",
                        "bounds": {
                          "top_left": {
                            "x": 373,
                            "y": 254
                          },
                          "top_right": {
                            "x": 391,
                            "y": 254
                          },
                          "bottom_right": {
                            "x": 391,
                            "y": 271
                          },
                          "bottom_left": {
                            "x": 372,
                            "y": 271
                          },
                          "width": 18.5,
                          "height": 17
                        },
                        "confidence": 0.99
                      }
                    ]
                  },
                  {
                    "text": "BALDWIN PARK CA 91706",
                    "bounds": {
                      "top_left": {
                        "x": 250,
                        "y": 270
                      },
                      "top_right": {
                        "x": 440,
                        "y": 269
                      },
                      "bottom_right": {
                        "x": 440,
                        "y": 286
                      },
                      "bottom_left": {
                        "x": 250,
                        "y": 287
                      },
                      "width": 190,
                      "height": 17
                    },
                    "average_confidence": 0.99,
                    "words": [
                      {
                        "text": "BALDWIN",
                        "bounds": {
                          "top_left": {
                            "x": 251,
                            "y": 271
                          },
                          "top_right": {
                            "x": 320,
                            "y": 270
                          },
                          "bottom_right": {
                            "x": 319,
                            "y": 287
                          },
                          "bottom_left": {
                            "x": 251,
                            "y": 287
                          },
                          "width": 68.5,
                          "height": 16.5
                        },
                        "confidence": 0.99
                      },
                      {
                        "text": "PARK",
                        "bounds": {
                          "top_left": {
                            "x": 327,
                            "y": 270
                          },
                          "top_right": {
                            "x": 365,
                            "y": 270
                          },
                          "bottom_right": {
                            "x": 365,
                            "y": 287
                          },
                          "bottom_left": {
                            "x": 326,
                            "y": 287
                          },
                          "width": 38.5,
                          "height": 17
                        },
                        "confidence": 0.99
                      },
                      {
                        "text": "CA",
                        "bounds": {
                          "top_left": {
                            "x": 372,
                            "y": 270
                          },
                          "top_right": {
                            "x": 392,
                            "y": 270
                          },
                          "bottom_right": {
                            "x": 392,
                            "y": 287
                          },
                          "bottom_left": {
                            "x": 372,
                            "y": 287
                          },
                          "width": 20,
                          "height": 17
                        },
                        "confidence": 1
                      },
                      {
                        "text": "91706",
                        "bounds": {
                          "top_left": {
                            "x": 397,
                            "y": 270
                          },
                          "top_right": {
                            "x": 439,
                            "y": 269
                          },
                          "bottom_right": {
                            "x": 438,
                            "y": 287
                          },
                          "bottom_left": {
                            "x": 396,
                            "y": 287
                          },
                          "width": 42,
                          "height": 17.5
                        },
                        "confidence": 0.99
                      }
                    ]
                  },
                  {
                    "text": "DOB 09/12/1987",
                    "bounds": {
                      "top_left": {
                        "x": 251,
                        "y": 291
                      },
                      "top_right": {
                        "x": 404,
                        "y": 289
                      },
                      "bottom_right": {
                        "x": 404,
                        "y": 311
                      },
                      "bottom_left": {
                        "x": 251,
                        "y": 313
                      },
                      "width": 153,
                      "height": 22
                    },
                    "average_confidence": 0.99,
                    "words": [
                      {
                        "text": "DOB",
                        "bounds": {
                          "top_left": {
                            "x": 252,
                            "y": 293
                          },
                          "top_right": {
                            "x": 285,
                            "y": 292
                          },
                          "bottom_right": {
                            "x": 285,
                            "y": 312
                          },
                          "bottom_left": {
                            "x": 252,
                            "y": 313
                          },
                          "width": 33,
                          "height": 20
                        },
                        "confidence": 1
                      },
                      {
                        "text": "09/12/1987",
                        "bounds": {
                          "top_left": {
                            "x": 291,
                            "y": 291
                          },
                          "top_right": {
                            "x": 404,
                            "y": 290
                          },
                          "bottom_right": {
                            "x": 404,
                            "y": 312
                          },
                          "bottom_left": {
                            "x": 291,
                            "y": 312
                          },
                          "width": 113,
                          "height": 21.5
                        },
                        "confidence": 0.99
                      }
                    ]
                  },
                  {
                    "text": "RSTRNONE 09121987",
                    "bounds": {
                      "top_left": {
                        "x": 251,
                        "y": 314
                      },
                      "top_right": {
                        "x": 343,
                        "y": 314
                      },
                      "bottom_right": {
                        "x": 343,
                        "y": 330
                      },
                      "bottom_left": {
                        "x": 251,
                        "y": 331
                      },
                      "width": 92,
                      "height": 16.5
                    },
                    "average_confidence": 0.96,
                    "words": [
                      {
                        "text": "RSTRNONE",
                        "bounds": {
                          "top_left": {
                            "x": 252,
                            "y": 315
                          },
                          "top_right": {
                            "x": 341,
                            "y": 314
                          },
                          "bottom_right": {
                            "x": 341,
                            "y": 331
                          },
                          "bottom_left": {
                            "x": 251,
                            "y": 331
                          },
                          "width": 89.5,
                          "height": 16.5
                        },
                        "confidence": 0.96
                      }
                    ]
                  },
                  {
                    "text": "Ivan M.",
                    "bounds": {
                      "top_left": {
                        "x": 76,
                        "y": 374
                      },
                      "top_right": {
                        "x": 239,
                        "y": 376
                      },
                      "bottom_right": {
                        "x": 239,
                        "y": 420
                      },
                      "bottom_left": {
                        "x": 75,
                        "y": 419
                      },
                      "width": 163.5,
                      "height": 44.5
                    },
                    "average_confidence": 0.9,
                    "words": [
                      {
                        "text": "Ivan",
                        "bounds": {
                          "top_left": {
                            "x": 85,
                            "y": 375
                          },
                          "top_right": {
                            "x": 172,
                            "y": 376
                          },
                          "bottom_right": {
                            "x": 171,
                            "y": 419
                          },
                          "bottom_left": {
                            "x": 83,
                            "y": 420
                          },
                          "width": 87.5,
                          "height": 44
                        },
                        "confidence": 0.94
                      },
                      {
                        "text": "M.",
                        "bounds": {
                          "top_left": {
                            "x": 199,
                            "y": 377
                          },
                          "top_right": {
                            "x": 237,
                            "y": 379
                          },
                          "bottom_right": {
                            "x": 237,
                            "y": 420
                          },
                          "bottom_left": {
                            "x": 198,
                            "y": 420
                          },
                          "width": 38.5,
                          "height": 42
                        },
                        "confidence": 0.87
                      }
                    ]
                  },
                  {
                    "text": "SEX M HAIR BLK EYES BLK",
                    "bounds": {
                      "top_left": {
                        "x": 315,
                        "y": 369
                      },
                      "top_right": {
                        "x": 370,
                        "y": 369
                      },
                      "bottom_right": {
                        "x": 370,
                        "y": 384
                      },
                      "bottom_left": {
                        "x": 315,
                        "y": 384
                      },
                      "width": 55,
                      "height": 15
                    },
                    "average_confidence": 0.99,
                    "words": [
                      {
                        "text": "SEX",
                        "bounds": {
                          "top_left": {
                            "x": 317,
                            "y": 370
                          },
                          "top_right": {
                            "x": 345,
                            "y": 370
                          },
                          "bottom_right": {
                            "x": 345,
                            "y": 385
                          },
                          "bottom_left": {
                            "x": 317,
                            "y": 385
                          },
                          "width": 28,
                          "height": 15
                        },
                        "confidence": 0.98
                      },
                      {
                        "text": "M",
                        "bounds": {
                          "top_left": {
                            "x": 356,
                            "y": 370
                          },
                          "top_right": {
                            "x": 364,
                            "y": 370
                          },
                          "bottom_right": {
                            "x": 364,
                            "y": 385
                          },
                          "bottom_left": {
                            "x": 356,
                            "y": 385
                          },
                          "width": 8,
                          "height": 15
                        },
                        "confidence": 1
                      }
                    ]
                  },
                  {
                    "text": "HGT 5-02\" WGT 185lb ISS",
                    "bounds": {
                      "top_left": {
                        "x": 316,
                        "y": 387
                      },
                      "top_right": {
                        "x": 400,
                        "y": 387
                      },
                      "bottom_right": {
                        "x": 400,
                        "y": 401
                      },
                      "bottom_left": {
                        "x": 316,
                        "y": 402
                      },
                      "width": 84,
                      "height": 14.5
                    },
                    "average_confidence": 0.82,
                    "words": [
                      {
                        "text": "HGT",
                        "bounds": {
                          "top_left": {
                            "x": 317,
                            "y": 388
                          },
                          "top_right": {
                            "x": 347,
                            "y": 387
                          },
                          "bottom_right": {
                            "x": 346,
                            "y": 402
                          },
                          "bottom_left": {
                            "x": 317,
                            "y": 402
                          },
                          "width": 29.5,
                          "height": 14.5
                        },
                        "confidence": 0.99
                      },
                      {
                        "text": "5-02\"",
                        "bounds": {
                          "top_left": {
                            "x": 359,
                            "y": 387
                          },
                          "top_right": {
                            "x": 399,
                            "y": 387
                          },
                          "bottom_right": {
                            "x": 399,
                            "y": 402
                          },
                          "bottom_left": {
                            "x": 359,
                            "y": 401
                          },
                          "width": 40,
                          "height": 14.5
                        },
                        "confidence": 0.65
                      }
                    ]
                  },
                  {
                    "text": "DD 08/13/202160648/AAFD/27 07/25/2022",
                    "bounds": {
                      "top_left": {
                        "x": 316,
                        "y": 408
                      },
                      "top_right": {
                        "x": 499,
                        "y": 406
                      },
                      "bottom_right": {
                        "x": 499,
                        "y": 421
                      },
                      "bottom_left": {
                        "x": 316,
                        "y": 423
                      },
                      "width": 183,
                      "height": 15
                    },
                    "average_confidence": 0.95,
                    "words": [
                      {
                        "text": "DD",
                        "bounds": {
                          "top_left": {
                            "x": 318,
                            "y": 408
                          },
                          "top_right": {
                            "x": 335,
                            "y": 408
                          },
                          "bottom_right": {
                            "x": 336,
                            "y": 423
                          },
                          "bottom_left": {
                            "x": 318,
                            "y": 423
                          },
                          "width": 17.5,
                          "height": 15
                        },
                        "confidence": 0.96
                      },
                      {
                        "text": "08/13/202160648/AAFD/27",
                        "bounds": {
                          "top_left": {
                            "x": 342,
                            "y": 408
                          },
                          "top_right": {
                            "x": 499,
                            "y": 407
                          },
                          "bottom_right": {
                            "x": 499,
                            "y": 420
                          },
                          "bottom_left": {
                            "x": 343,
                            "y": 423
                          },
                          "width": 156.5,
                          "height": 14
                        },
                        "confidence": 0.94
                      }
                    ]
                  }
                ]
              }
            ],
            "width": 698,
            "height": 525
          }
        }
      ]
    }
  },
  "finishReason": "stop",
  "usage": {
    "inputTokens": 16771,
    "outputTokens": 2530,
    "totalTokens": 19301
  }
}
  • name: The name of the specialized task ran (e.g., ocr, object_detection, speech_to_text)
  • precontext can contain multiple items of the same task name if the task was performed multiple times
  • result: The raw metadata for that task
  • Each result is task specific and contains the raw metadata for that task.
  • Every task has a different result structure but the structure is fixed and predictable for each task type.

STT & Translation Precontext Example

Note: LangChain SDK does not provide an official way to access raw API responses, so we cannot include an example for that SDK at this time.

OpenAI SDK

Vercel AI SDK

LangChain SDK

import { z } from "zod";
import { zodResponseFormat } from "openai/helpers/zod";

const STTSchema = z.object({
	translated_text: z.string().describe("translated text"),
	original_language_code: z.string(),
	translated_language_code: z.string(),
});

const response = await interfaze.chat.completions.create({
	model: "interfaze-beta",
	messages: [
		{
			role: "user",
			content: "Transcribe the audio file and translate it to chinese https://r2public.jigsawstack.com/interfaze/examples/stt_medical_short.mp4",
		},
	],
	response_format: zodResponseFormat(STTSchema, "stt_schema"),
});

console.log(response.choices[0].message.content);

//@ts-expect-error precontext is not typed
const precontext = response.precontext;
console.log("STT Results:", precontext?.[0]?.result);

In this example, we're transcribing an audio file and translating the text to Chinese. You will notice two items in the precontext array, one for the STT task and one for the translation task along side your final response content.

{
  "object": {
    "translated_text": "我刚开始服用一轮阿莫西林,想问一下把它和我目前的螺内酯处方一起服用是否安全。",
    "original_language_code": "en",
    "translated_language_code": "zh"
  },
  "response": {
    "id": "interfaze-1775088833045",
    "modelId": "interfaze-beta",
    "body": {
      "id": "interfaze-1775088833045",
      "object": "chat.completion",
      "model": "interfaze-beta",
      "usage": {
        "prompt_tokens": 2758,
        "completion_tokens": 800,
        "total_tokens": 3558
      },
      "precontext": [
        {
          "name": "stt",
          "result": {
            "text": "I just started a round of amoxicillin and I wanted to ask if it was safe to take that with my current spironolactone prescription.",
            "chunks": [
              {
                "timestamp": [0.28, 4],
                "text": "I just started a round of amoxicillin and I wanted to ask"
              },
              {
                "timestamp": [4, 7.72],
                "text": "if it was safe to take that with my current spironolactone prescription."
              }
            ]
          }
        },
        {
          "name": "translate",
          "result": {
            "translated_text": "我刚开始服用一轮阿莫西林,想问一下把它和我目前的螺内酯处方一起服用是否安全。",
            "source_language": "auto-detected",
            "target_language": "zh",
            "batch_size": 1
          }
        }
      ]
    }
  },
  "finishReason": "stop",
  "usage": {
    "inputTokens": 2758,
    "outputTokens": 800,
    "totalTokens": 3558
  }
}

Enabling Precontext in streaming responses

By default, streaming responses don't return precontext since the client will not be able to process the data separately from the main response.

However, you can enable it by including the x-show-additional-info header in your API requests.

This will stream the precontext data as a single chunk before the main response begins streaming.

headers: {
  "x-show-additional-info": "true"
}

In streaming mode, the precontext data is sent as a single chunk before the main response begins streaming. This chunk follows a structured format that encapsulates all pre-processing information upfront.

<precontext>
{
  "name": "process_name",
  "result": { /* detailed process output */ }
}
</precontext>

Getting Precontext as the main response

You can use run tasks to run a specific task without having to run the full model making it faster and cheaper. However it is limited to the raw output provided in precontext with a fixed predefined structured output.

Learn more about running a task.