Python
from openlayer import Openlayer
# Let's say we want to stream the following row, which represents a model prediction:
data = {
"user_query": "what's the meaning of life?",
"output": "42",
"tokens": 7,
"cost": 0.02,
"timestamp": 1620000000
}
# Prepare the config for the data, which depends on your project's task type. In this
# case, we have an LLM project:
from openlayer.types.inference_pipelines import data_stream_params
config = data_stream_params.ConfigLlmData(
input_variable_names=["user_query"],
output_column_name="output",
num_of_token_column_name="tokens",
cost_column_name="cost",
timestamp_column_name="timestamp",
prompt=[{"role": "user", "content": "{{ user_query }}"}],
)
client = Openlayer()
data_stream_response = client.inference_pipelines.data.stream(
inference_pipeline_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
rows=[data],
config=config,
)
import Openlayer from 'openlayer';
const openlayer = new Openlayer();
await openlayer.inferencePipelines.data.stream(
{
inferencePipelineId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
config: {
inputVariableNames: ['user_query'],
outputColumnName: 'output',
numOfTokenColumnName: 'tokens',
costColumnName: 'cost',
timestampColumnName: 'timestamp',
prompt: [{ role: 'user', content: '{{ user_query }}' }],
},
rows: [
{
user_query: "what's the meaning of life?",
output: '42',
tokens: 7,
cost: 0.02,
timestamp: 1620000000,
},
],
},
);
package main
import (
"context"
"github.com/openlayer-ai/openlayer-go"
"github.com/openlayer-ai/openlayer-go/option"
)
client := openlayer.NewClient()
inferencePipelineDataStreamResponse, err := client.InferencePipelines.Data.Stream(
context.TODO(),
inferencePipelineId: "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
openlayer.InferencePipelineDataStreamParams{
Config: openlayer.F[openlayer.InferencePipelineDataStreamParamsConfigUnion](openlayer.InferencePipelineDataStreamParamsConfigLlmData{
OutputColumnName: openlayer.F("output"),
NumOfTokenColumnName: openlayer.F("tokens"),
CostColumnName: openlayer.F("cost"),
TimestampColumnName: openlayer.F("timestamp"),
}),
Rows: openlayer.F([]map[string]interface{}{map[string]interface{}{
"user_query": "what's the meaning of life?",
"output": "42",
"tokens": 7,
"cost": 0.02,
"timestamp": 1620000000,
}}),
},
)
if err != nil {
panic(err.Error())
}
import com.openlayer.api.client.OpenlayerClient;
import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
import com.openlayer.api.models.InferencePipelineDataStreamParams;
import com.openlayer.api.models.InferencePipelineDataStreamResponse;
import java.util.List;
OpenlayerClient client = OpenlayerOkHttpClient.fromEnv();
// Let's say this is the row with the relevant fields
InferencePipelineDataStreamParams.Row row = InferencePipelineDataStreamParams.Row.builder()
.putAdditionalProperty("user_query", JsonString.of("what's the meaning of life?"))
.putAdditionalProperty("output", JsonString.of("42"))
.putAdditionalProperty("tokens", JsonNumber.of(7))
.putAdditionalProperty("cost", JsonNumber.of(0.02))
.build();
// Create Inference Pipeline Data Stream Parameters
InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.builder()
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.config(InferencePipelineDataStreamParams.Config.ofLlmData(InferencePipelineDataStreamParams.Config.LlmData.builder()
.outputColumnName("output")
.costColumnName("cost")
.inputVariableNames(List.of("user_query"))
.numOfTokenColumnName("tokens")
.timestampColumnName("timestamp")
.build()))
.row(List.of(InferencePipelineDataStreamParams.Row.builder().build()))
.build();
// Make the request
InferencePipelineDataStreamResponse inferencePipelineDataStreamResponse =
client.inferencePipelines().data().stream(params);
curl --request POST \
--url https://api.openlayer.com/v1/inference-pipelines/{inferencePipelineId}/data-stream \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"rows": [
{
"user_query": "what is the meaning of life?",
"output": "42",
"tokens": 7,
"cost": 0.02,
"timestamp": 1620000000
}
],
"config": {
"prompt": [
{
"role": "user",
"content": "{{ user_query }}"
}
],
"inputVariableNames": [
"user_query"
],
"outputColumnName": "output",
"timestampColumnName": "timestamp",
"costColumnName": "cost",
"numOfTokenColumnName": "tokens"
}
}'
{
"success": true
}{
"code": 123,
"error": "<string>"
}Monitoring
Publish records
Publish records to a data source (formerly known as “inference pipeline”).
Python
from openlayer import Openlayer
# Let's say we want to stream the following row, which represents a model prediction:
data = {
"user_query": "what's the meaning of life?",
"output": "42",
"tokens": 7,
"cost": 0.02,
"timestamp": 1620000000
}
# Prepare the config for the data, which depends on your project's task type. In this
# case, we have an LLM project:
from openlayer.types.inference_pipelines import data_stream_params
config = data_stream_params.ConfigLlmData(
input_variable_names=["user_query"],
output_column_name="output",
num_of_token_column_name="tokens",
cost_column_name="cost",
timestamp_column_name="timestamp",
prompt=[{"role": "user", "content": "{{ user_query }}"}],
)
client = Openlayer()
data_stream_response = client.inference_pipelines.data.stream(
inference_pipeline_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
rows=[data],
config=config,
)
import Openlayer from 'openlayer';
const openlayer = new Openlayer();
await openlayer.inferencePipelines.data.stream(
{
inferencePipelineId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
config: {
inputVariableNames: ['user_query'],
outputColumnName: 'output',
numOfTokenColumnName: 'tokens',
costColumnName: 'cost',
timestampColumnName: 'timestamp',
prompt: [{ role: 'user', content: '{{ user_query }}' }],
},
rows: [
{
user_query: "what's the meaning of life?",
output: '42',
tokens: 7,
cost: 0.02,
timestamp: 1620000000,
},
],
},
);
package main
import (
"context"
"github.com/openlayer-ai/openlayer-go"
"github.com/openlayer-ai/openlayer-go/option"
)
client := openlayer.NewClient()
inferencePipelineDataStreamResponse, err := client.InferencePipelines.Data.Stream(
context.TODO(),
inferencePipelineId: "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
openlayer.InferencePipelineDataStreamParams{
Config: openlayer.F[openlayer.InferencePipelineDataStreamParamsConfigUnion](openlayer.InferencePipelineDataStreamParamsConfigLlmData{
OutputColumnName: openlayer.F("output"),
NumOfTokenColumnName: openlayer.F("tokens"),
CostColumnName: openlayer.F("cost"),
TimestampColumnName: openlayer.F("timestamp"),
}),
Rows: openlayer.F([]map[string]interface{}{map[string]interface{}{
"user_query": "what's the meaning of life?",
"output": "42",
"tokens": 7,
"cost": 0.02,
"timestamp": 1620000000,
}}),
},
)
if err != nil {
panic(err.Error())
}
import com.openlayer.api.client.OpenlayerClient;
import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
import com.openlayer.api.models.InferencePipelineDataStreamParams;
import com.openlayer.api.models.InferencePipelineDataStreamResponse;
import java.util.List;
OpenlayerClient client = OpenlayerOkHttpClient.fromEnv();
// Let's say this is the row with the relevant fields
InferencePipelineDataStreamParams.Row row = InferencePipelineDataStreamParams.Row.builder()
.putAdditionalProperty("user_query", JsonString.of("what's the meaning of life?"))
.putAdditionalProperty("output", JsonString.of("42"))
.putAdditionalProperty("tokens", JsonNumber.of(7))
.putAdditionalProperty("cost", JsonNumber.of(0.02))
.build();
// Create Inference Pipeline Data Stream Parameters
InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.builder()
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.config(InferencePipelineDataStreamParams.Config.ofLlmData(InferencePipelineDataStreamParams.Config.LlmData.builder()
.outputColumnName("output")
.costColumnName("cost")
.inputVariableNames(List.of("user_query"))
.numOfTokenColumnName("tokens")
.timestampColumnName("timestamp")
.build()))
.row(List.of(InferencePipelineDataStreamParams.Row.builder().build()))
.build();
// Make the request
InferencePipelineDataStreamResponse inferencePipelineDataStreamResponse =
client.inferencePipelines().data().stream(params);
curl --request POST \
--url https://api.openlayer.com/v1/inference-pipelines/{inferencePipelineId}/data-stream \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"rows": [
{
"user_query": "what is the meaning of life?",
"output": "42",
"tokens": 7,
"cost": 0.02,
"timestamp": 1620000000
}
],
"config": {
"prompt": [
{
"role": "user",
"content": "{{ user_query }}"
}
],
"inputVariableNames": [
"user_query"
],
"outputColumnName": "output",
"timestampColumnName": "timestamp",
"costColumnName": "cost",
"numOfTokenColumnName": "tokens"
}
}'
{
"success": true
}{
"code": 123,
"error": "<string>"
}Use this endpoint to stream individual inference data points to Openlayer.
If you want to upload many inferences in one go, please use the batch upload method instead.
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your workspace API key. See Find your API key for more information.
Path Parameters
The inference pipeline id (a UUID).
Body
application/json
A list of inference data points with inputs and outputs
Example:
[ { "user_query": "what is the meaning of life?", "output": "42", "tokens": 7, "cost": 0.02, "timestamp": 1620000000 } ]
Configuration for the data stream. Depends on your Openlayer project task type.
- LLM
- Tabular classification
- Tabular regression
- Text classification
Show child attributes
Show child attributes
Example:
{ "prompt": [ { "role": "user", "content": "{{ user_query }}" } ], "inputVariableNames": ["user_query"], "outputColumnName": "output", "timestampColumnName": "timestamp", "costColumnName": "cost", "numOfTokenColumnName": "tokens" }
Response
Status OK.
Available options:
true Was this page helpful?
⌘I

