Class: SafetyKit::Resources::Streams

Inherits:
Object
  • Object
show all
Defined in:
lib/safety_kit/resources/streams.rb,
sig/safety_kit/resources/streams.rbs

Overview

Ingest and monitor livestream content.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Streams

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Streams.

Parameters:



134
135
136
# File 'lib/safety_kit/resources/streams.rb', line 134

def initialize(client:)
  @client = client
end

Instance Method Details

#add(namespace, id:, stream_url:, request_options: {}) ⇒ SafetyKit::Models::StreamAddResponse

Monitor the livestream at the given stream URL. This method returns immediately.

Errors: 400 for an invalid body, with the reason in the message. 401 for a missing Authorization header. 403 for an invalid API key. 429 when the rate limit is exceeded. 5xx for transient internal failures. Retry 429 and 5xx with exponential backoff. Do not retry other 4xx errors, they indicate a problem with the request.

Parameters:

  • namespace (String)

    The namespace to ingest stream data into

  • id (String)
  • stream_url (String)
  • request_options (SafetyKit::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



28
29
30
31
32
33
34
35
36
37
# File 'lib/safety_kit/resources/streams.rb', line 28

def add(namespace, params)
  parsed, options = SafetyKit::StreamAddParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/streams/%1$s", namespace],
    body: parsed,
    model: SafetyKit::Models::StreamAddResponse,
    options: options
  )
end

#add_frame(namespace, image_data_uri:, stream_id:, timestamp:, frame_id: nil, metadata: nil, request_options: {}) ⇒ SafetyKit::Models::StreamAddFrameResponse

Some parameter documentations has been truncated, see Models::StreamAddFrameParams for more details.

Ingest a single livestream frame as an image data URI plus relative timestamp in milliseconds. The stream does not need to be created beforehand. Only image/jpeg, image/png, and image/webp are accepted. The decoded bytes must match the declared mime type, decode as a valid image, stay within 5 MB, and stay within 4096x4096 / 16,000,000 total pixels. Timestamps are relative milliseconds from stream start and must be unique and strictly increasing within a stream. Duplicate or out-of-order frame timestamps are accepted at the API boundary but ignored by downstream processing. This method returns immediately after the frame has been accepted for processing.

Errors: 400 for an invalid body or an image that fails validation, with the reason in the message. 401 for a missing Authorization header. 403 for an invalid API key. 429 when the rate limit is exceeded. 5xx for transient internal failures. Retry 429 and 5xx with exponential backoff. Frame ingestion is idempotent, so a retried request that already succeeded is ignored. Do not retry other 4xx errors, they indicate a problem with the request.

Parameters:

  • namespace (String)

    The namespace to ingest stream data into

  • image_data_uri (String)

    A data URI containing a base64-encoded frame image. Only image/jpeg, image/png,

  • stream_id (String)
  • timestamp (Integer)
  • frame_id (String)
  • metadata (Hash{Symbol=>Object, nil})

    Arbitrary key-value metadata to associate with this frame, at most 8192 bytes wh

  • request_options (SafetyKit::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



78
79
80
81
82
83
84
85
86
87
# File 'lib/safety_kit/resources/streams.rb', line 78

def add_frame(namespace, params)
  parsed, options = SafetyKit::StreamAddFrameParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/streams/%1$s/frames", namespace],
    body: parsed,
    model: SafetyKit::Models::StreamAddFrameResponse,
    options: options
  )
end

#add_transcript(namespace, stream_id:, text:, timestamp:, transcript_id: nil, request_options: {}) ⇒ SafetyKit::Models::StreamAddTranscriptResponse

Ingest a single transcript segment for a livestream using a relative timestamp in milliseconds. The stream does not need to be created beforehand. Transcript timestamps are relative milliseconds from stream start and should be monotonically increasing within a stream so transcript context lines up correctly with later frames. This method returns immediately after the transcript has been accepted for processing.

Errors: 400 for an invalid body, with the reason in the message. 401 for a missing Authorization header. 403 for an invalid API key. 429 when the rate limit is exceeded. 5xx for transient internal failures. Retry 429 and 5xx with exponential backoff. Transcript ingestion is idempotent, so a retried request that already succeeded is ignored. Do not retry other 4xx errors, they indicate a problem with the request.

Parameters:

  • namespace (String)

    The namespace to ingest stream data into

  • stream_id (String)
  • text (String)
  • timestamp (Integer)
  • transcript_id (String)
  • request_options (SafetyKit::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



120
121
122
123
124
125
126
127
128
129
# File 'lib/safety_kit/resources/streams.rb', line 120

def add_transcript(namespace, params)
  parsed, options = SafetyKit::StreamAddTranscriptParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/streams/%1$s/transcripts", namespace],
    body: parsed,
    model: SafetyKit::Models::StreamAddTranscriptResponse,
    options: options
  )
end