# Class AsyncPrompts (1.153.1)

1.153.1 (latest) 1.153.0 1.152.0 1.151.0 1.150.0 1.149.0 1.148.1 1.147.0 1.146.0 1.145.0 1.144.0 1.143.0 1.142.0 1.141.0 1.140.0 1.139.0 1.138.0 1.137.0 1.136.0 1.135.0 1.134.0 1.133.0 1.132.0 1.131.0 1.130.0 1.129.0 1.122.0 1.121.0 1.120.0 1.119.0 1.118.0 1.117.0 1.95.1 1.94.0 1.93.1 1.92.0 1.91.0 1.90.0 1.89.0 1.88.0 1.87.0 1.86.0 1.85.0 1.84.0 1.83.0 1.82.0 1.81.0 1.80.0 1.79.0 1.78.0 1.77.0 1.76.0 1.75.0 1.74.0 1.73.0 1.72.0 1.71.1 1.70.0 1.69.0 1.68.0 1.67.1 1.66.0 1.65.0 1.63.0 1.62.0 1.60.0 1.59.0

    AsyncPrompts(api_client_: google.genai._api_client.BaseApiClient)

API documentation for `AsyncPrompts` class.

## Methods

### create

    create(
        *,
        prompt: typing.Union[
            vertexai._genai.types.common.Prompt, vertexai._genai.types.common.PromptDict
        ],
        config: typing.Optional[
            typing.Union[
                vertexai._genai.types.common.CreatePromptConfig,
                vertexai._genai.types.common.CreatePromptConfigDict,
            ]
        ] = None
    ) -> vertexai._genai.types.common.Prompt

Creates a new prompt in a Vertex Dataset resource.

This method waits for prompt creation to be complete before returning.

Note: This method does not create a versioned resource for your prompt.
Call create_version() to create a new prompt resource with a version.

### create_version

    create_version(
        *,
        prompt: typing.Union[
            vertexai._genai.types.common.Prompt, vertexai._genai.types.common.PromptDict
        ],
        prompt_id: typing.Optional[str] = None,
        config: typing.Optional[
            typing.Union[
                vertexai._genai.types.common.CreatePromptVersionConfig,
                vertexai._genai.types.common.CreatePromptVersionConfigDict,
            ]
        ] = None
    ) -> vertexai._genai.types.common.Prompt

Creates a prompt resource and an initial prompt version.

When creating new prompt and prompt version resources, this waits for
the create operation to complete before returning.

Note: This method is recommended instead of create() since it creates a
versioned resource for your prompt.

### delete

    delete(
        *,
        prompt_id: str,
        config: typing.Optional[vertexai._genai.types.common.DeletePromptConfig] = None
    ) -> None

Deletes a prompt resource.

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `TimeoutError` | If the delete operation does not complete within the timeout. |
| `ValueError` | If the delete operation fails. |

### delete_version

    delete_version(
        *,
        prompt_id: str,
        version_id: str,
        config: typing.Optional[vertexai._genai.types.common.DeletePromptConfig] = None
    ) -> None

Deletes a prompt version resource.

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `TimeoutError` | If the delete operation does not complete within the timeout. |
| `ValueError` | If the delete operation fails. |

### get

    get(
        *,
        prompt_id: str,
        config: typing.Optional[vertexai._genai.types.common.GetPromptConfig] = None
    ) -> vertexai._genai.types.common.Prompt

Gets a prompt resource from a Vertex Dataset.

### get_version

    get_version(
        *,
        prompt_id: str,
        version_id: str,
        config: typing.Optional[vertexai._genai.types.common.GetPromptConfig] = None
    ) -> vertexai._genai.types.common.Prompt

Gets a prompt resource from a Vertex Dataset.

### launch_optimization_job

    launch_optimization_job(
        method: vertexai._genai.types.common.PromptOptimizerMethod,
        config: typing.Union[
            vertexai._genai.types.common.PromptOptimizerConfig,
            vertexai._genai.types.common.PromptOptimizerConfigDict,
        ],
    ) -> vertexai._genai.types.common.CustomJob

Call async Vertex AI Prompt Optimizer (VAPO).

Note: The `wait_for_completion` parameter in the config will be
ignored when using the AsyncClient, as it is not supported.

Example usage:
client = [vertexai.Client](https://docs.cloud.google.com/python/docs/reference/vertexai/latest/vertexai.Client)(project=PROJECT_NAME, location='us-central1')
vapo_config = vertexai.types.PromptOptimizerConfig(
config_path='gs://you-bucket-name/your-config.json',
service_account=service_account,
)
job = await client.aio.prompts.launch_optimization_job(
method=types.PromptOptimizerMethod.VAPO, config=vapo_config)

### list

    list(
        *,
        config: typing.Optional[
            typing.Union[
                vertexai._genai.types.common.ListPromptsConfig,
                vertexai._genai.types.common.ListPromptsConfigDict,
            ]
        ] = None
    ) -> typing.AsyncIterator[vertexai._genai.types.common.PromptRef]

Lists prompt resources in a project.

This method retrieves all the prompts from the project provided in the
[vertexai.Client](https://docs.cloud.google.com/python/docs/reference/vertexai/latest/vertexai.Client) constructor and returns a list of prompt references containing the prompt_id and model for the prompt.

To get the full types.Prompt resource for a PromptRef after calling this method, use the get() method with the prompt_id as the prompt_id argument.
Example usage:

    prompt_refs = client.aio.prompt_management.list_prompts()
    async for prompt_ref in prompt_refs:
      await client.prompt_management.get(prompt_id=prompt_ref.prompt_id)

### list_versions

    list_versions(
        *,
        prompt_id: str,
        config: typing.Optional[
            typing.Union[
                vertexai._genai.types.common.ListPromptsConfig,
                vertexai._genai.types.common.ListPromptsConfigDict,
            ]
        ] = None
    ) -> typing.AsyncIterator[vertexai._genai.types.common.PromptVersionRef]

Lists prompt version resources for a provided prompt_id.

This method retrieves all the prompt versions for a provided prompt_id.

To get the full types.Prompt resource for a PromptVersionRef after calling this method, use the get() method with the returned prompt_id and version_id.
Example usage:

    prompt_version_refs = await client.prompt_management.list_versions(prompt_id="123")
    async for version_ref in prompt_version_refs:
      await client.aio.prompt_management.get(prompt_id=version_ref.prompt_id, version_id=version_ref.version_id)

### optimize

    optimize(
        *,
        prompt: str,
        config: typing.Optional[
            typing.Union[
                vertexai._genai.types.common.OptimizeConfig,
                vertexai._genai.types.common.OptimizeConfigDict,
            ]
        ] = None
    ) -> vertexai._genai.types.common.OptimizeResponse

Makes an async request to the optimizePrompt endpoint and returns an optimized prompt.

Example usage:
client = [vertexai.Client](https://docs.cloud.google.com/python/docs/reference/vertexai/latest/vertexai.Client)(project=PROJECT_NAME, location='us-central1')
prompt = "Generate system instructions for analyzing medical articles"
response = await client.aio.prompts.optimize(prompt=prompt)

### restore_version

    restore_version(
        *,
        prompt_id: str,
        version_id: str,
        config: typing.Optional[vertexai._genai.types.common.RestoreVersionConfig] = None
    ) -> vertexai._genai.types.common.Prompt

Restores the provided prompt version to the latest version.

### update

    update(
        *,
        prompt_id: str,
        prompt: typing.Union[
            vertexai._genai.types.common.Prompt, vertexai._genai.types.common.PromptDict
        ],
        config: typing.Optional[
            typing.Union[
                vertexai._genai.types.common.UpdatePromptConfig,
                vertexai._genai.types.common.UpdatePromptConfigDict,
            ]
        ] = None
    ) -> vertexai._genai.types.common.Prompt

Updates an existing prompt and creates a new version for the prompt
associated with the provided prompt_id.