Simplify your webhook integration with AgentMark’s webhook helpers.
@agentmark/vercel-ai-v4-webhook-helper
package is designed to work seamlessly with the Vercel AI SDK. It abstracts away the complexity of handling different prompt types, allowing you to use a single method to run any prompt.
WebhookHelper
class inspects the incoming prompt’s configuration (text_config
, object_config
, etc.) and automatically calls the appropriate handler (runTextPrompt
, runObjectPrompt
, etc.). This means you don’t have to write repetitive boilerplate code to handle each prompt type manually.
WebhookHelper
.
agentmark
client, you can instantiate the WebhookHelper
and use it to process incoming webhook events. The example below shows a complete Next.js App Router endpoint.
runPrompt
MethodrunPrompt
method is the core of the helper when handling single prompt runs. It takes two arguments:
event.data
: The prompt data from the webhook payload.options
(optional): An object to configure the prompt execution.options
object allows you to specify how the prompt should be run.
shouldStream
(boolean): Defaults to true
. When true
, the method returns a ReadableStream
to stream the response back to the AgentMark platform. This is the recommended approach for real-time feedback. Set to false
to receive the full response as a single JSON object after the model has finished generating.runPrompt
method returns a promise that resolves to a WebhookResponse
. Your webhook must handle the response correctly to ensure proper communication with the AgentMark platform.
response.type
is stream
: You must return a new Response
object. The body should be the response.stream
and the headers must include response.streamHeader
. This is critical for streaming the result back to AgentMark correctly.
response.type
is anything else (text
, object
, image
, speech
): You should return the entire response
object as a JSON response.
runDataset
MethodrunDataset
method handles running a prompt against all items in a dataset. It is a “fire-and-forget” operation from the webhook’s perspective. The helper processes the entire dataset in the background and sends telemetry data to AgentMark for each item.
event.data
, which is an object containing the paths to the prompt and dataset, along with run metadata.
runDataset
method returns a Promise<RunDatasetResponse>
that contains a streaming response. The helper processes the entire dataset and streams the results back to AgentMark in real-time.
runDataset
method currently supports prompts that generate text and objects. Image and speech generation prompts are not supported for dataset runs.WebhookHelper
or are not using the Vercel AI SDK, you can implement the event handling logic yourself. Please refer to our detailed event documentation for guidance:
We’re here to help! Choose the best way to reach us: