You can provide a custom callback that takes the store object as a parameter instead of using the Lira integrated storing system and dashboard. This allows you to store the message object in your database, so the data never leaves your server.

Callback function

The callback function is used to store the message object in your database or any other storage system. The callback function receives the store object as a parameter. The store object is a data structure that holds the input, output, request time, and error of a message.

{
  input: LiraMessageInputStore;
  output?: LiraMessageOutputStore;
  reqTime?: LiraMessageReqTimesStore;
  error?: unknown;
}
The callback is NOT awaited, to avoid blocking the main thread.

Store object

The store object is a data structure that holds the input, output, request time, and error of a message.

const lira = new Lira({
  store: {
    disabled?: boolean // default: false
    callback: async (data) => {
      console.log(data)
    }
  }
})
input
LiraMessageInputStore
required

The same input object that was sent to the model to generate the response. Input object schema.
Pluse the optional provider field that holds the provider that was used to generate the response.

{
  lira?: LiraMetadata
  max_tokens?: number
  messages: Array<Message>
  model: AnthropicModels | OpenAIModels
  provider?: "Anthropic" | "OpenAI" | string
  temperature?: number
  top_p?: number
  tools?: Array<Tool>
  tool_choice?: ToolChoice
  stop_sequences?: Array<string>
  stream?: boolean
  openai_options?: OpenAIOptions
  anthropic_options?: AnthropicOptions
}
output
LiraMessageOutputStore

The same output object that was generated by the model, described in the stream section. Output object stream schema.

{
  id?: string
  model?: string
  message: AssistantResponse | ToolUseResponse
  stop_reason?: StopReason
  stop_sequence?: string
  usage?: Usage
  logprobs?: Logprobs
  openai_options?: OpenAIOptions
}
reqTime
LiraMessageReqTimesStore

The request time object holds the time range it took to generate the response.

{ 
  start: number;
  end: number;
}
error
unknown

The error object holds the error that was thrown during the generation of the response.