> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Publish records

> Publish records to a data source (formerly known as "inference pipeline").

<Note>
  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](https://github.com/openlayer-ai/openlayer-python/blob/main/examples/monitoring/upload_batch_data.py) instead.
</Note>


## OpenAPI

````yaml post /inference-pipelines/{inferencePipelineId}/data-stream
openapi: 3.0.3
info:
  contact:
    email: support@openlayer.com
    name: Openlayer
    url: https://openlayer.com/
  description: API for interacting with the Openlayer server.
  title: Openlayer API
  version: '1.0'
  x-logo:
    url: https://logo.clearbit.com/openlayer.com
servers:
  - url: https://api.openlayer.com/v1
    description: Our prod backend
security:
  - bearerAuth: []
paths:
  /inference-pipelines/{inferencePipelineId}/data-stream:
    post:
      tags:
        - Monitoring
      summary: Publish inference
      description: Publish an inference data point to an inference pipeline.
      operationId: streamData
      parameters:
        - $ref: '#/components/parameters/inferencePipelineId'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  description: 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
                  nullable: false
                  items:
                    type: object
                    additionalProperties: true
                config:
                  oneOf:
                    - $ref: '#/components/schemas/LLMData'
                    - $ref: '#/components/schemas/TabularClassificationData'
                    - $ref: '#/components/schemas/TabularRegressionData'
                    - $ref: '#/components/schemas/TextClassificationData'
                  example:
                    prompt:
                      - role: user
                        content: '{{ user_query }}'
                    inputVariableNames:
                      - user_query
                    outputColumnName: output
                    timestampColumnName: timestamp
                    costColumnName: cost
                    numOfTokenColumnName: tokens
                  description: >-
                    Configuration for the data stream. Depends on your
                    **Openlayer project task type**.
              required:
                - rows
                - config
      responses:
        '200':
          description: Status OK.
          content:
            application/json:
              schema:
                type: object
                required:
                  - success
                properties:
                  success:
                    type: boolean
                    enum:
                      - true
        '500':
          $ref: '#/components/responses/UnexpectedError'
      x-codeSamples:
        - lang: python
          source: >
            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,
            )
        - lang: typescript
          source: |
            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,
                  },
                ],
              },
            );
        - lang: go
          source: >
            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())
            }
        - lang: java
          source: >
            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);
        - lang: curl
          source: |
            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"
              }
            }'
components:
  parameters:
    inferencePipelineId:
      name: inferencePipelineId
      in: path
      description: The inference pipeline id (a UUID).
      required: true
      schema:
        type: string
        format: uuid
  schemas:
    LLMData:
      title: LLM
      type: object
      properties:
        numOfTokenColumnName:
          type: string
          description: Name of the column with the total number of tokens.
          example: num_tokens
          nullable: true
        contextColumnName:
          type: string
          description: >-
            Name of the column with the context retrieved. Applies to RAG use
            cases. Providing the context enables RAG-specific metrics.
          example: context
        costColumnName:
          type: string
          description: Name of the column with the cost associated with each row.
          example: cost
        groundTruthColumnName:
          type: string
          description: Name of the column with the ground truths.
          example: ground_truth
        inferenceIdColumnName:
          type: string
          description: >-
            Name of the column with the inference ids. This is useful if you
            want to update rows at a later point in time. If not provided, a
            unique id is generated by Openlayer.
          example: id
        inputVariableNames:
          type: array
          description: >-
            Array of input variable names. Each input variable should be a
            dataset column.
          example:
            - user_query
          items:
            type: string
        latencyColumnName:
          type: string
          description: Name of the column with the latencies.
          example: latency
        metadata:
          type: object
          description: Object with metadata.
        outputColumnName:
          type: string
          description: Name of the column with the model outputs.
          example: output
        prompt:
          type: array
          description: Prompt for the LLM.
          example:
            - role: user
              content: '{{ user_query }}'
          items:
            type: object
            properties:
              role:
                type: string
                description: Role of the prompt.
                example: user
              content:
                type: string
                description: Content of the prompt.
                example: '{{ user_query }}'
        questionColumnName:
          type: string
          description: >-
            Name of the column with the questions. Applies to RAG use cases.
            Providing the question enables RAG-specific metrics.
          example: question
        timestampColumnName:
          type: string
          description: >-
            Name of the column with the timestamps. Timestamps must be in UNIX
            sec format. If not provided, the upload timestamp is used.
          example: timestamp
        userIdColumnName:
          type: string
          description: Name of the column with the user id.
          nullable: true
          example: user_id
        sessionIdColumnName:
          type: string
          description: Name of the column with the session id.
          nullable: true
          example: session_id
      required:
        - outputColumnName
    TabularClassificationData:
      title: Tabular classification
      type: object
      properties:
        categoricalFeatureNames:
          type: array
          description: >-
            Array with the names of all categorical features in the dataset.
            E.g. ["Age", "Geography"].
          example:
            - Geography
          items:
            type: string
        classNames:
          type: array
          description: >-
            List of class names indexed by label integer in the dataset. E.g.
            ["Retained", "Exited"] when 0, 1 are in your label column.
          example:
            - Retained
            - Exited
          items:
            type: string
        featureNames:
          type: array
          description: Array with all input feature names.
          example:
            - Age
            - Geography
          items:
            type: string
        inferenceIdColumnName:
          type: string
          description: >-
            Name of the column with the inference ids. This is useful if you
            want to update rows at a later point in time. If not provided, a
            unique id is generated by Openlayer.
          example: id
        labelColumnName:
          type: string
          description: >-
            Name of the column with the labels. The data in this column must be
            **zero-indexed integers**, matching the list provided in
            `classNames`.
          example: label
        latencyColumnName:
          type: string
          description: Name of the column with the latencies.
          example: latency
        metadata:
          type: object
          description: Object with metadata.
        predictionsColumnName:
          type: string
          description: >-
            Name of the column with the model's predictions as **zero-indexed
            integers**.
          example: prediction
        predictionScoresColumnName:
          type: string
          description: >-
            Name of the column with the model's predictions as **lists of class
            probabilities**.
          example: prediction_scores
        timestampColumnName:
          type: string
          description: >-
            Name of the column with the timestamps. Timestamps must be in UNIX
            sec format. If not provided, the upload timestamp is used.
          example: timestamp
      required:
        - classNames
    TabularRegressionData:
      title: Tabular regression
      type: object
      properties:
        categoricalFeatureNames:
          type: array
          description: >-
            Array with the names of all categorical features in the dataset.
            E.g. ["Gender", "Geography"].
          example:
            - Gender
            - Geography
          items:
            type: string
        featureNames:
          type: array
          description: Array with all input feature names.
          items:
            type: string
        inferenceIdColumnName:
          type: string
          description: >-
            Name of the column with the inference ids. This is useful if you
            want to update rows at a later point in time. If not provided, a
            unique id is generated by Openlayer.
          example: id
        latencyColumnName:
          type: string
          description: Name of the column with the latencies.
          example: latency
        metadata:
          type: object
          description: Object with metadata.
        predictionsColumnName:
          type: string
          description: Name of the column with the model's predictions.
          example: prediction
        targetColumnName:
          type: string
          description: Name of the column with the targets (ground truth values).
          example: target
        timestampColumnName:
          type: string
          description: >-
            Name of the column with the timestamps. Timestamps must be in UNIX
            sec format. If not provided, the upload timestamp is used.
          example: timestamp
    TextClassificationData:
      title: Text classification
      type: object
      properties:
        classNames:
          type: array
          description: >-
            List of class names indexed by label integer in the dataset. E.g.
            ["Retained", "Exited"] when 0, 1 are in your label column.
          example:
            - Retained
            - Exited
          items:
            type: string
        inferenceIdColumnName:
          type: string
          description: >-
            Name of the column with the inference ids. This is useful if you
            want to update rows at a later point in time. If not provided, a
            unique id is generated by Openlayer.
          example: id
        labelColumnName:
          type: string
          description: >-
            Name of the column with the labels. The data in this column must be
            **zero-indexed integers**, matching the list provided in
            `classNames`.
          example: label
        latencyColumnName:
          type: string
          description: Name of the column with the latencies.
          example: latency
        metadata:
          type: object
          description: Object with metadata.
        predictionsColumnName:
          type: string
          description: >-
            Name of the column with the model's predictions as **zero-indexed
            integers**.
          example: prediction
        predictionScoresColumnName:
          type: string
          description: >-
            Name of the column with the model's predictions as **lists of class
            probabilities**.
          example: prediction_scores
        textColumnName:
          type: string
          description: Name of the column with the text data.
          example: user_query
        timestampColumnName:
          type: string
          description: >-
            Name of the column with the timestamps. Timestamps must be in UNIX
            sec format. If not provided, the upload timestamp is used.
          example: timestamp
      required:
        - classNames
  responses:
    UnexpectedError:
      description: Unexpected error.
      content:
        application/json:
          schema:
            type: object
            required:
              - code
              - error
            properties:
              code:
                type: integer
                format: int32
              error:
                type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your workspace API key. See [Find your API
        key](https://www.openlayer.com/docs/workspace-and-projects/find-your-api-key)
        for more information.

````