Skip to content

create_event async

create_event(
    space_id: SpaceId,
    actor_id: ActorId,
    payload: EventPayload,
    *,
    config_overrides: Optional[AsyncOpenSearchMemoryClientConfig] = None,
    session_id: Optional[SessionId] = None,
    event_timestamp: Optional[EventTimestamp] = None,
    metadata: Optional[MetadataMap] = None,
    client_token: Optional[ClientToken] = None,
    infer: Optional[bool] = None,
) -> CreateEventOutput

Submits an event (conversation turns, structured data, or a PDF document stored in Amazon S3) to a session in a space.

The operation returns as soon as the event is saved. GetEvent and ListEvents return it immediately. SearchEvents returns it after it's indexed. SearchMemories returns memories extracted from it only after a strategy's extraction trigger fires and the memories are indexed.

If the space uses a customer managed AWS KMS key, the call can also fail because of the key. It fails with AccessDeniedException if you aren't allowed to use the key, and with ThrottlingException if AWS KMS throttles the request. It fails with ValidationException if the key is disabled, pending deletion, or deleted.

Parameters:

  • space_id (SpaceId) –

    The ID of the space that owns the event, for example sp-02864597b164.

  • actor_id (ActorId) –

    The ID of the actor (end user or agent) that the event belongs to.

  • session_id (Optional[SessionId], default: None ) –

    The session the event belongs to. Send every event of one conversation with the same session ID, so that SUMMARY strategies summarize the conversation as one session. If you omit it, the service generates a session ID and returns it.

  • event_timestamp (Optional[EventTimestamp], default: None ) –

    When the event occurred. The default is the time that the service receives the request.

  • payload (EventPayload) –

    The event content. Set exactly one union member.

  • metadata (Optional[MetadataMap], default: None ) –

    Metadata tags to store with the event. Memories derived from the event carry the same tags. Keys that begin with x-amz-, the keys documentS3Source and documentS3Url, and other keys that the service uses internally are reserved: a request that sets one fails with ValidationException, and the message names the key.

    A space can use at most 50 distinct metadata keys across all of its events and memories. A request that would add a key beyond that fails with ValidationException. Reuse an existing key instead.

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier that makes the request idempotent. Within 2 hours of the first request, a retry with the same token and the same request, including the same sessionId, returns the same event. If you omit sessionId, the service generates a new one on each attempt, so a retry fails with ConflictException. Reusing the token with different request content also fails with ConflictException. eventTimestamp isn't compared. After 2 hours, the token starts a new event.

  • infer (Optional[bool], default: None ) –

    Specifies whether to extract memories from this event. The default is true. Set it to false to store the event without extraction: the service skips strategies that infer memories, and still indexes the event's turns for SearchEvents. A document submitted as a blob is still extracted.

Raises:

  • AccessDeniedException –

    You don't have sufficient access to perform this operation. To use this operation, you must have AWS Identity and Access Management (IAM) permissions for the operation, and on the resource it acts on. If the space uses a customer managed AWS Key Management Service (AWS KMS) key, you must also have permission to use the key.

  • ConflictException –

    The request conflicts with the current state of the resource. For example, the space is being created, updated, or deleted, a space with the same name already exists, or you reused a client token with different parameters. Wait for the space to finish being created, updated, or deleted, or use a different name or client token, and then retry.

  • InternalServerException –

    The service couldn't process the request because of an internal error. Retry the request.

  • ResourceNotFoundException –

    The specified resource doesn't exist. Check the IDs in the request.

  • ThrottlingException –

    The service throttled the request. Retry the request with exponential backoff.

  • ValidationException –

    The request isn't valid. The reason, message, and fieldList members describe the problem. Fix the request, and then try again.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_opensearchmemory/_services/async_open_search_memory.py
async def create_event(
    self,
    space_id: "capo_opensearchmemory.types.space_id.SpaceId",
    actor_id: "capo_opensearchmemory.types.actor_id.ActorId",
    payload: "capo_opensearchmemory.types.event_payload.EventPayload",
    *,
    config_overrides: Optional[AsyncOpenSearchMemoryClientConfig] = None,
    session_id: Optional["capo_opensearchmemory.types.session_id.SessionId"] = None,
    event_timestamp: Optional[
        "capo_opensearchmemory.types.event_timestamp.EventTimestamp"
    ] = None,
    metadata: Optional[
        "capo_opensearchmemory.types.metadata_map.MetadataMap"
    ] = None,
    client_token: Optional[
        "capo_opensearchmemory.types.client_token.ClientToken"
    ] = None,
    infer: Optional[bool] = None,
) -> "capo_opensearchmemory.types.create_event_output.CreateEventOutput":
    """<p>Submits an event (conversation turns, structured data, or a PDF document stored in Amazon S3) to a session in a space.</p> <p>The operation returns as soon as the event is saved. <code>GetEvent</code> and <code>ListEvents</code> return it immediately. <code>SearchEvents</code> returns it after it's indexed. <code>SearchMemories</code> returns memories extracted from it only after a strategy's extraction trigger fires and the memories are indexed.</p> <p>If the space uses a customer managed AWS KMS key, the call can also fail because of the key. It fails with <code>AccessDeniedException</code> if you aren't allowed to use the key, and with <code>ThrottlingException</code> if AWS KMS throttles the request. It fails with <code>ValidationException</code> if the key is disabled, pending deletion, or deleted.</p>

    Args:
        space_id: <p>The ID of the space that owns the event, for example <code>sp-02864597b164</code>.</p>
        actor_id: <p>The ID of the actor (end user or agent) that the event belongs to.</p>
        session_id: <p>The session the event belongs to. Send every event of one conversation with the same session ID, so that <code>SUMMARY</code> strategies summarize the conversation as one session. If you omit it, the service generates a session ID and returns it.</p>
        event_timestamp: <p>When the event occurred. The default is the time that the service receives the request.</p>
        payload: <p>The event content. Set exactly one union member.</p>
        metadata: <p>Metadata tags to store with the event. Memories derived from the event carry the same tags. Keys that begin with <code>x-amz-</code>, the keys <code>documentS3Source</code> and <code>documentS3Url</code>, and other keys that the service uses internally are reserved: a request that sets one fails with <code>ValidationException</code>, and the message names the key.</p> <p>A space can use at most 50 distinct metadata keys across all of its events and memories. A request that would add a key beyond that fails with <code>ValidationException</code>. Reuse an existing key instead.</p>
        client_token: <p>A unique, case-sensitive identifier that makes the request idempotent. Within 2 hours of the first request, a retry with the same token and the same request, including the same <code>sessionId</code>, returns the same event. If you omit <code>sessionId</code>, the service generates a new one on each attempt, so a retry fails with <code>ConflictException</code>. Reusing the token with different request content also fails with <code>ConflictException</code>. <code>eventTimestamp</code> isn't compared. After 2 hours, the token starts a new event.</p>
        infer: <p>Specifies whether to extract memories from this event. The default is <code>true</code>. Set it to <code>false</code> to store the event without extraction: the service skips strategies that infer memories, and still indexes the event's turns for <code>SearchEvents</code>. A document submitted as a <code>blob</code> is still extracted.</p>

    Raises:
        capo_opensearchmemory.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access to perform this operation. To use this operation, you must have AWS Identity and Access Management (IAM) permissions for the operation, and on the resource it acts on. If the space uses a customer managed AWS Key Management Service (AWS KMS) key, you must also have permission to use the key.</p>
        capo_opensearchmemory.errors.conflict_exception.ConflictException: <p>The request conflicts with the current state of the resource. For example, the space is being created, updated, or deleted, a space with the same name already exists, or you reused a client token with different parameters. Wait for the space to finish being created, updated, or deleted, or use a different name or client token, and then retry.</p>
        capo_opensearchmemory.errors.internal_server_exception.InternalServerException: <p>The service couldn't process the request because of an internal error. Retry the request.</p>
        capo_opensearchmemory.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource doesn't exist. Check the IDs in the request.</p>
        capo_opensearchmemory.errors.throttling_exception.ThrottlingException: <p>The service throttled the request. Retry the request with exponential backoff.</p>
        capo_opensearchmemory.errors.validation_exception.ValidationException: <p>The request isn't valid. The <code>reason</code>, <code>message</code>, and <code>fieldList</code> members describe the problem. Fix the request, and then try again.</p>
        capo_opensearchmemory.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_opensearchmemory.types.create_event_input.CreateEventInput]",
    ) -> AsyncOperationResponse[
        "capo_opensearchmemory.types.create_event_output.CreateEventOutput"
    ]:
        import capo_opensearchmemory._operations.open_search_memory.create_event

        (
            output,
            http_response,
        ) = await capo_opensearchmemory._operations.open_search_memory.create_event.async_create_event(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_opensearchmemory.types.create_event_input.CreateEventInput",
    ) -> dict[str, Any]:
        import capo_opensearchmemory.types.create_event_input

        return capo_opensearchmemory.types.create_event_input.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateEvent", redact_input=_redact_input),
    )
    input_: capo_opensearchmemory.types.create_event_input.CreateEventInput = {
        "space_id": space_id,
        "actor_id": actor_id,
        "payload": payload,
    }
    if session_id is not None:
        input_["session_id"] = session_id
    if event_timestamp is not None:
        input_["event_timestamp"] = event_timestamp
    if metadata is not None:
        input_["metadata"] = metadata
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if infer is not None:
        input_["infer"] = infer

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output