HTTP data sources

EXTERNAL_HTTP() lets FeatureQL fetch data from REST APIs, microservices, and any HTTP endpoint. This is useful for integrating third-party services, calling internal microservices, or querying ML model endpoints as part of a feature computation.

Creating an HTTP source

Define a reusable HTTP endpoint with SOURCE_HTTP():

FeatureQL
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.HTTP_SOURCE AS
SOURCE_HTTP(
    'http://host.docker.internal:18010/hello'
    WITH (
        query_params=ROW('default' AS "name"),
        timeout='500ms'
    )
);
Result
feature_name VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.EXTERNAL_HTTP.HTTP_SOURCECREATEDFeature created as not exists

The source captures the base URL, default query parameters, and timeout. These defaults apply to every request unless overridden at call time.

Install the source synchronously in a local development serving process:

FeatureQL
RECOMPILE SERVING;
Result
FEATURE VARCHARKIND VARCHARSTATUS VARCHARMESSAGE VARCHARSINCE VARCHAR
FM.TUTORIALS.EXTERNAL_HTTP.HTTP_SOURCESOURCE_HTTPLOADED

Making requests with EXTERNAL_HTTP()

Use EXTERNAL_HTTP() to call the endpoint with dynamic parameters:

FeatureQL
DEFINE
    firstname := INPUT(VARCHAR)
RETURN
    firstname,
    http_response := EXTERNAL_HTTP(
        FROM fm.tutorials.external_http.http_source
        WITH (
            QUERY_PARAMS = ROW(firstname AS name)
        )
    )[value]
FOR
    firstname := BIND_VALUES(ARRAY('Alice', 'Bob', 'Charlie'))
;
Result
FIRSTNAME VARCHARHTTP_RESPONSE VARCHAR
AliceHello Alice!
BobHello Bob!
CharlieHello Charlie!

The query_params in the request override the defaults from the source definition. For each input value, FeatureMesh issues a separate HTTP request — FIRSTNAME := 'Alice' becomes GET http://host.docker.internal:18010/hello?name=Alice, and so on.

EXTERNAL_HTTP() returns a ROW(value JSON): read the answer with [value], and parse structured responses with JSON_PARSE_AS() to get a typed row. If a request fails (timeout, network error, non-2xx response), the query fails with that error: a missing answer is never turned into NULL silently. To handle failures instead, read the row's source_status (OK, MISS, TIMEOUT, UNAVAILABLE or ERROR): it guards the read, so on a failed request the value is NULL, the status says why, and the call succeeds ( Errors and fallbacks ).

What goes where

Every property can be set on the source, as a default for all calls, or on the call, from the row's values:

PropertyOn the sourceOn the call
methodDefault method ('GET' if none)Replaces it
pathAppended to the base URLResolved against the base URL: '/v1/risk' replaces its path, 'risk' is relative to it
headersROW of VARCHAR: sent with every callAdded to the source's
query_paramsROW of VARCHAROverride the source's by name, the others kept
bodySent by calls that give none: ROW as a JSON object, VARCHAR as isReplaces the source's: ROW sent as a JSON object, or a VARCHAR sent as is
timeoutPer request, such as '500ms'Replaces the source's for this call

Query parameters and header values are text in HTTP, so they must be VARCHAR: cast numbers with ::VARCHAR. A number is refused rather than dropped:

FeatureQL
RETURN
    greeting := EXTERNAL_HTTP(
        FROM fm.tutorials.external_http.http_source
        WITH (
            QUERY_PARAMS = ROW(42 AS name)
        )
    )
;
Result
ERROR UE/EXTERNAL-HTTP-WRONG-TYPE_2

Sending a JSON body

Most APIs that take more than a name or two take a POST with a JSON body. Here a fraud-risk API expects:

{
  "model": "fraud-v4",
  "customer": {"id": 11, "country": "FR", "account_age_days": 12},
  "order": {"amount": 800.0, "country": "US"}
}
json

and answers {"model": "fraud-v4", "score": 1.0, "reasons": ["large_amount", ...]}. The source holds what every call shares: the method, the path and a version header.

FeatureQL
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.RISK_API AS
SOURCE_HTTP(
    'http://host.docker.internal:18010'
    WITH (
        method = 'POST',
        path = '/v1/risk',
        headers = ROW('2' AS "x-api-version"),
        timeout = '500ms'
    )
);
Result
feature_name VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.EXTERNAL_HTTP.RISK_APICREATEDFeature created as not exists

The feature describes the call. The body is a ROW whose shape is the JSON object: each AS names a field, a nested ROW is a nested object, an ARRAY a JSON array, and a constant such as the model name is just a value. Names that are FeatureQL keywords, such as order, are quoted. JSON_PARSE_AS() types the answer:

FeatureQL
CREATE OR REPLACE FEATURES IN FM.TUTORIALS.EXTERNAL_HTTP AS
PERSIST
    ORDER_ID := INPUT(BIGINT),
    CUSTOMER_ID := INPUT(BIGINT),
    CUSTOMER_COUNTRY := INPUT(VARCHAR),
    ACCOUNT_AGE_DAYS := INPUT(BIGINT),
    AMOUNT := INPUT(DOUBLE),
    ORDER_COUNTRY := INPUT(VARCHAR),
    ORDER_RISK := JSON_PARSE_AS(
        EXTERNAL_HTTP(
            FROM RISK_API
            WITH (body = ROW(
                'fraud-v4' AS model,
                ROW(CUSTOMER_ID AS id, CUSTOMER_COUNTRY AS country, ACCOUNT_AGE_DAYS AS account_age_days) AS customer,
                ROW(AMOUNT AS amount, ORDER_COUNTRY AS country) AS "order"
            ))
        )[value] AS ROW(model VARCHAR, score DOUBLE, reasons ARRAY(VARCHAR))
    );
Result
feature_name VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.EXTERNAL_HTTP.ACCOUNT_AGE_DAYSCREATEDFeature created as not exists
FM.TUTORIALS.EXTERNAL_HTTP.AMOUNTCREATEDFeature created as not exists
FM.TUTORIALS.EXTERNAL_HTTP.CUSTOMER_COUNTRYCREATEDFeature created as not exists
FM.TUTORIALS.EXTERNAL_HTTP.CUSTOMER_IDCREATEDFeature created as not exists
FM.TUTORIALS.EXTERNAL_HTTP.ORDER_COUNTRYCREATEDFeature created as not exists
FM.TUTORIALS.EXTERNAL_HTTP.ORDER_IDCREATEDFeature created as not exists
FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISKCREATEDFeature created as not exists

Six inputs describe an order. A query binds them together, one row per order, and FeatureMesh sends one POST per row:

FeatureQL
RETURN
    fm.tutorials.external_http.order_id,
    model := fm.tutorials.external_http.order_risk[model],
    score := fm.tutorials.external_http.order_risk[score],
    reasons := fm.tutorials.external_http.order_risk[reasons]
FOR
    (fm.tutorials.external_http.order_id, fm.tutorials.external_http.customer_id, fm.tutorials.external_http.customer_country, fm.tutorials.external_http.account_age_days, fm.tutorials.external_http.amount, fm.tutorials.external_http.order_country) := BIND_VALUES(
        ARRAY(
            ROW(1, 10, 'FR', 400, 20.0e0, 'FR'),
            ROW(2, 11, 'FR', 12, 800.0e0, 'US')
        )
    )
;
Result
ORDER_ID BIGINTMODEL VARCHARSCORE DOUBLEREASONS VARBINARY
1fraud-v40.1[]
2fraud-v41.0[large_amount, foreign_country, new_account]

From a prepared statement

In production, the caller sends the orders and nothing else. Group the six inputs in USING, so that they form one input table:

FeatureQL
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK_PS AS
PREPARED_STATEMENT(
    FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK
    USING (
        FM.TUTORIALS.EXTERNAL_HTTP.ORDER_ID,
        FM.TUTORIALS.EXTERNAL_HTTP.CUSTOMER_ID,
        FM.TUTORIALS.EXTERNAL_HTTP.CUSTOMER_COUNTRY,
        FM.TUTORIALS.EXTERNAL_HTTP.ACCOUNT_AGE_DAYS,
        FM.TUTORIALS.EXTERNAL_HTTP.AMOUNT,
        FM.TUTORIALS.EXTERNAL_HTTP.ORDER_COUNTRY
    )
);
Result
feature_name VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK_PSCREATEDFeature created as not exists

Each row of input_1 lists one order's values in the order of USING:

Prepared
FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK_PS
Call 1
{"input_1": [[1, 10, "FR", 400, 20.0, "FR"], [3, 12, "DE", 90, 650.0, "DE"]]}
ORDER_ID BIGINTCUSTOMER_ID BIGINTCUSTOMER_COUNTRY VARCHARACCOUNT_AGE_DAYS BIGINTAMOUNT DOUBLEORDER_COUNTRY VARCHARORDER_RISK_PS ROW
110FR40020.0FR{model: fraud-v4, score: 0.1, reasons: []}
312DE90650.0DE{model: fraud-v4, score: 0.4, reasons: [large_amount]}

The same call with curl:

curl -X POST "http://localhost:10090/v1/featureql" \
  -H "Content-Type: application/json" \
  -d '{
    "statement": {
      "id": "FM.TUTORIALS.EXTERNAL_HTTP.ORDER_RISK_PS",
      "inputs": {
        "input_1": [
          [1, 10, "FR", 400, 20.0, "FR"],
          [3, 12, "DE", 90, 650.0, "DE"]
        ]
      }
    }
  }'
bash

Listing the inputs separately, USING (ORDER_ID), (CUSTOMER_ID), ..., would make six input tables combined by cross product: right for independent inputs, wrong for the fields of one order.

Several rows per call

One request per input row is fine for a few rows, but an endpoint that scores a list — a model server ranking 200 candidates, a bulk lookup API — should get the rows in one call. The source's batch property sends up to size rows per request:

FeatureQL
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.HELLO_MODEL AS
SOURCE_HTTP(
    'http://host.docker.internal:18010/v1/models/hello:predict'
    WITH (
        method='POST',
        batch=ROW(64 AS size),
        timeout='500ms'
    )
);
Result
feature_name VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.EXTERNAL_HTTP.HELLO_MODELCREATEDFeature created as not exists

FeatureQL
DEFINE
    firstname := INPUT(VARCHAR)
RETURN
    firstname,
    greeting := EXTERNAL_HTTP(
        FROM fm.tutorials.external_http.hello_model
        WITH (
            BODY = ROW(firstname AS name)
        )
    )[value]
FOR
    firstname := BIND_VALUES(ARRAY('Alice', 'Bob', 'Charlie'))
;
Result
FIRSTNAME VARCHARGREETING VARCHAR
AliceHello Alice!
BobHello Bob!
CharlieHello Charlie!

The rows that share method, URL and headers go together: each row's JSON body becomes one element of an array, and the answer must hold one result per row in an array, in the same order — position matches a result to its row. A result that is a JSON string comes back as its text, any other value as JSON, and null as NULL. An answer without exactly one result per row fails the query.

Where the arrays sit depends on the endpoint:

PropertyDefaultMeaning
sizerequiredRows per call at most
request_field'instances'Field of the request object holding the rows' bodies; '' sends the bare array
response_field'predictions'Field (or dotted path, such as 'data.scores') of the answer holding the results; '' when the answer is the bare array

The defaults are the KServe v1 / TF Serving prediction protocol, {"instances": [...]} in and {"predictions": [...]} out, which most model servers speak. With request_field='', response_field='', the source posts [body, ...] and reads [result, ...].

A batch endpoint of your own

The risk API above also has a batch endpoint, with its own field names: it takes {"rows": [body, ...]} and answers {"data": {"scores": [result, ...]}}. The source says so:

FeatureQL
CREATE OR REPLACE FEATURE FM.TUTORIALS.EXTERNAL_HTTP.RISK_BATCH_API AS
SOURCE_HTTP(
    'http://host.docker.internal:18010/v1/risk:batch'
    WITH (
        method = 'POST',
        batch = ROW(100 AS size, 'rows' AS request_field, 'data.scores' AS response_field),
        timeout = '500ms'
    )
);
Result
feature_name VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.EXTERNAL_HTTP.RISK_BATCH_APICREATEDFeature created as not exists

The feature is written exactly as for one row per call: the same nested body, the same JSON_PARSE_AS() of one result. Only the source changes, and the three orders go in one POST:

FeatureQL
DEFINE
    order_risk_batch := JSON_PARSE_AS(
        EXTERNAL_HTTP(
            FROM fm.tutorials.external_http.risk_batch_api
            WITH (
                BODY = ROW(
                    ROW(
                        fm.tutorials.external_http.customer_id AS id,
                        fm.tutorials.external_http.customer_country AS country,
                        fm.tutorials.external_http.account_age_days AS account_age_days
                    ) AS customer,
                    ROW(
                        fm.tutorials.external_http.amount AS amount,
                        fm.tutorials.external_http.order_country AS country
                    ) AS order
                )
            )
        )[value] AS ROW<score DOUBLE, reasons ARRAY<VARCHAR>>
    )
RETURN
    fm.tutorials.external_http.order_id,
    score := order_risk_batch[score],
    reasons := order_risk_batch[reasons]
FOR
    (fm.tutorials.external_http.order_id, fm.tutorials.external_http.customer_id, fm.tutorials.external_http.customer_country, fm.tutorials.external_http.account_age_days, fm.tutorials.external_http.amount, fm.tutorials.external_http.order_country) := BIND_VALUES(
        ARRAY(
            ROW(1, 10, 'FR', 400, 20.0e0, 'FR'),
            ROW(2, 11, 'FR', 12, 800.0e0, 'US'),
            ROW(3, 12, 'DE', 90, 650.0e0, 'DE')
        )
    )
;
Result
ORDER_ID BIGINTSCORE DOUBLEREASONS VARBINARY
10.1[]
21.0[large_amount, foreign_country, new_account]
30.4[large_amount]

Moving a feature from per-row calls to batches is a change of source, not of the feature.

Authenticated calls

Put the token in the source's headers, read with SECRET() from the serving engine's environment or a mounted file, so the registry never holds it:

SCORING_API := SOURCE_HTTP(
    'https://scoring.internal/v1/score'
    WITH (
        method = 'POST',
        headers = ROW('Bearer ' || SECRET('env', 'SCORING_API_TOKEN') AS "Authorization"),
        timeout = '200ms'
    )
)

When a rotated token applies, and what an unset variable does, is in Credentials .

Performance considerations

Parallelization: FeatureMesh issues the requests of a query concurrently, up to 32 at a time, whether each carries one row or a batch.

Batching: When the endpoint accepts lists, set batch on the source. 200 rows become one or a few calls instead of 200.

No retries: There is no built-in retry policy. If reliability is critical, put a retry-capable proxy or load balancer in front of the target service.

Related