Skip to content


api api

txtai has a full-featured API, backed by FastAPI, that can optionally be enabled for any txtai process. All functionality found in txtai can be accessed via the API.

The following is an example configuration and startup script for the API.

Note: This configuration file enables all functionality. For memory-bound systems, splitting pipelines into multiple instances is a best practice.

# Index file path
path: /tmp/index

# Allow indexing of documents
writable: True

# Enbeddings index
  path: sentence-transformers/nli-mpnet-base-v2

# Extractive QA
  path: distilbert-base-cased-distilled-squad

# Zero-shot labeling

# Similarity

# Text segmentation
    sentences: true

# Text summarization

# Text extraction
    paragraphs: true
    minlength: 100
    join: true

# Transcribe audio to text

# Translate text between languages

# Workflow definitions
            - action: textractor
              task: url
            - action: summary
            - action: translation
              args: ["fr"]
            - action: textractor
              task: url
            - action: summary
            - action: translation
              args: ["es"]

Assuming this YAML content is stored in a file named config.yml, the following command starts the API process.

CONFIG=config.yml uvicorn "txtai.api:app"

uvicorn is a full-featured production ready server with support for SSL and more. See the uvicorn deployment guide for details.

Connect to API

The default port for the API is 8000. See the uvicorn link above to change this.

txtai has a number of language bindings which abstract the API (see links below). Alternatively, code can be written to connect directly to the API. Documentation for a live running instance can be found at the /docs url (i.e. http://localhost:8000/docs). The following example runs a workflow using cURL.

curl \
  -X POST "http://localhost:8000/workflow" \
  -H "Content-Type: application/json" \
  -d '{"name":"sumfrench", "elements": [""]}'

Local instance

A local instance can be instantiated. In this case, a txtai application runs internally, without any network connections, providing the same consolidated functionality. This enables running txtai in Python with configuration.

The configuration above can be run in Python with:

from import Application

# Load and run workflow
app = Application(config.yml)
app.workflow("sumfrench", [""])

See this link for a full list of methods.

Run with containers

The API can be containerized and run. This will bring up an API instance without having to install Python, txtai or any dependencies on your machine!

See this section for more information.

Supported language bindings

The following programming languages have bindings with the txtai API:

See the link below for a detailed example covering how to use the API.

Notebook Description
API Gallery Using txtai in JavaScript, Java, Rust and Go Open In Colab