---
title: AiApi
summary: Java SDK: the AI - Artificial Intelligence operations, 1 method, each with its parameters, result and a complete example.
order: 22
languages: [java]
sdk-package: Java SDK · nl.bimbase.bimworks.sdk
link-terms: true
---

# AiApi

[[page:reference/sdk/java|Java SDK]] · `nl.bimbase.bimworks.sdk.api` · class · 1 method

Natural-language calls, for example to turn a sentence into a BQL query, a BVL visualisation or a BCL check

Construct it with the client of [[page:reference/sdk/java#connect|the connect step]]: `new AiApi(client)`. Each method is one operation of the [[page:api|API part]], where it runs on its page.

<table class="dense">
<thead><tr><th>Method</th><th>Operation</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>[[page:reference/sdk/java/aiapi#texttoaction|textToAction]]</code></td><td>[[openapi:TextToAction]]</td><td>Turn a sentence into a BIM.works action (BQL, BVL or BCL)</td></tr>
</tbody>
</table>

## `textToAction` {#texttoaction}

```java
public TextToActionResult textToAction(TextToActionRequest textToActionRequest) throws ApiException
```

Turn a sentence into a BIM.works action (BQL, BVL or BCL). Sends the text to the language model the instance is configured with (the account's default text-to-action model, else the server's `ai.default_text_to_action`) and returns the action it wrote: a BQL query, a BVL visualisation or a BCL check. The server parses and formats the code before it answers; code that does not parse goes back to the model once with the parser's error, and fails with 502 when the second answer does not parse either.

<table class="dense">
<tbody>
<tr><th>Operation</th><td>[[openapi:TextToAction]] · <code>POST /openapi/ai/TextToAction</code></td></tr>
<tr><th>Scope</th><td>[[scope:ai:use]]</td></tr>
</tbody>
</table>

### Parameters

<table class="dense">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>textToActionRequest</code></td><td><code>[[page:reference/sdk/java/models#TextToActionRequest|TextToActionRequest]]</code><span class="req">required</span></td><td>The request: its properties are those of the model, its JSON that of [[openapi:TextToAction]]'s request body.</td></tr>
</tbody>
</table>

### Returns

<code>[[page:reference/sdk/java/models#TextToActionResult|TextToActionResult]]</code> — The action

### Example

```java
import nl.bimbase.bimworks.sdk.api.AiApi;
import nl.bimbase.bimworks.sdk.api.AuthApi;
import nl.bimbase.bimworks.sdk.client.ApiClient;
import nl.bimbase.bimworks.sdk.model.Auth;
import nl.bimbase.bimworks.sdk.model.LoginWithApiTokenRequest;
import nl.bimbase.bimworks.sdk.model.TextToActionRequest;

public class Example {
    public static void main(String[] args) throws Exception {
        // 1. Connect to BIM.works and log in with your API token
        ApiClient client = new ApiClient();
        client.updateBaseUri("BIM_WORKS_ADDRESS/openapi");
        Auth auth = new AuthApi(client)
                .loginWithApiToken(new LoginWithApiTokenRequest().token("BIM_WORKS_API_TOKEN"))
                .getAuth();
        client.setRequestInterceptor(builder -> builder.setHeader("Authorization", "Bearer " + auth.getBase64()));

        // 2. The request
        TextToActionRequest request = client.getObjectMapper().readValue("""
                {
                  "input": "Show the external walls in red",
                  "models": [
                    {
                      "type": "VersionModelIdentifier",
                      "uuid": "BIM_WORKS_FIRST_MODEL"
                    }
                  ]
                }
                """, TextToActionRequest.class);

        // 3. The call
        var result = new AiApi(client).textToAction(request);

        // 4. The result
        System.out.println(client.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(result));
    }
}
```
