# Chalk SQL Reference: LLM Functions
source: https://docs.chalk.ai/chalksql-docs#section-llm-functions

## `ai_complete(prompt, model, ...+10)`
source: https://docs.chalk.ai/chalksql-docs#ai_complete

Alias for [openai_complete](https://docs.chalk.ai/chalksql-docs#openai_complete).

## `ai_complete_raw(prompt, model, ...+7)`
source: https://docs.chalk.ai/chalksql-docs#ai_complete_raw

Alias for [openai_complete_raw](https://docs.chalk.ai/chalksql-docs#openai_complete_raw).

## `bedrock_embed(text)`
source: https://docs.chalk.ai/chalksql-docs#bedrock_embed

Computes an Amazon Titan `text` embedding for the input string via AWS Bedrock and returns the embedding as a float vector.

**Parameters**

- `text`: `large_string`
  The input `text`.
- `model_id`: `large_string`
  The model identifier to invoke.
- `dimensions`: `int64` = `NULL`
  The embedding dimension count.
- `normalize`: `bool` = `NULL`
- `aws_access_key_id_override`: `large_string` = `NULL`
- `aws_secret_access_key_override`: `large_string` = `NULL`
- `aws_session_token_override`: `large_string` = `NULL`
- `aws_role_arn_override`: `large_string` = `NULL`
- `aws_region_override`: `large_string` = `NULL`
- `aws_profile_name_override`: `large_string` = `NULL`

## `bedrock_predict(body)`
source: https://docs.chalk.ai/chalksql-docs#bedrock_predict

Invokes an AWS Bedrock model via InvokeModel with the provided binary request `body` and returns the raw binary response `body`.

**Parameters**

- `body`: `large_binary`
  The request `body`.
- `model_id`: `large_string`
  The model identifier to invoke.
- `content_type`: `large_string` = `NULL`
  The request content type.
- `accept`: `large_string` = `NULL`
  The response MIME type to request.
- `aws_access_key_id_override`: `large_string` = `NULL`
- `aws_secret_access_key_override`: `large_string` = `NULL`
- `aws_session_token_override`: `large_string` = `NULL`
- `aws_role_arn_override`: `large_string` = `NULL`
- `aws_region_override`: `large_string` = `NULL`
- `aws_profile_name_override`: `large_string` = `NULL`

## `chalk_encoder(url, labels, text)`
source: https://docs.chalk.ai/chalksql-docs#chalk_encoder

Classifies ``text`` with the fine-tuned encoder at ``url`` (chalk-encoder:// or chalk-encoder+grpc[s]://): `label_index` indexes ``labels`` (a JSON array of the model's label names) and `probability` is that label's probability renormalized over ``labels``. A row is null where ``text`` is null; `error` is set on every row of a failed call. ``url`` and ``labels`` must be literals.

**Parameters**

- `url`: `large_string`
  The URL to request.
- `labels`: `large_string`
- `text`: `large_string`
  The input `text`.

## `decision_complete(state, questions)`
source: https://docs.chalk.ai/chalksql-docs#decision_complete

Alias of `prompt_jev`: asks Jev's structured-decision API a set of typed `questions` (noul/choice/score) about ``state`` and returns the answers as a JSON string alongside usage statistics.

**Parameters**

- `state`: `large_string`
  The current `state` value.
- `questions`: `large_string`
- `model`: `large_string` = `NULL`
- `api_server`: `large_string` = `NULL`
- `api_key`: `large_string` = `NULL`

## `onnx_run(state, observation, model_path)`
source: https://docs.chalk.ai/chalksql-docs#onnx_run

Runs one step of a recurrent ONNX model: new_state = graph(`state`, `observation`).

**Overloads**

#### `onnx_run(state, observation, model_path)`

**Parameters**

- `state`: `list<item: float>`
  The current `state` value.
- `observation`: `list<item: float>`
  The `observation` to feed into this step.
- `model_path`: `large_string`
  The path to the ONNX model file.

#### `onnx_run(state, observation, model_path)`

**Parameters**

- `state`: `list<item: double>`
  The current `state` value.
- `observation`: `list<item: double>`
  The `observation` to feed into this step.
- `model_path`: `large_string`
  The path to the ONNX model file.

#### `onnx_run(state, observation, model_path)`

**Parameters**

- `state`: `large_list<item: float>`
  The current `state` value.
- `observation`: `large_list<item: float>`
  The `observation` to feed into this step.
- `model_path`: `large_string`
  The path to the ONNX model file.

#### `onnx_run(state, observation, model_path)`

**Parameters**

- `state`: `large_list<item: double>`
  The current `state` value.
- `observation`: `large_list<item: double>`
  The `observation` to feed into this step.
- `model_path`: `large_string`
  The path to the ONNX model file.

## `openai_complete(prompt)`
source: https://docs.chalk.ai/chalksql-docs#openai_complete

Makes a completion request to OpenAI's chat API and returns the response.

**Parameters**

- `prompt`: `large_string`
- `model`: `large_string` = `NULL`
- `api_server`: `large_string` = `NULL`
- `api_key`: `large_string` = `NULL`
- `max_tokens`: `int64` = `NULL`
- `temperature`: `double` = `NULL`
- `service_tier`: `large_string` = `NULL`
- `response_format`: `large_string` = `NULL`
- `chat_template_kwargs`: `large_string` = `NULL`
- `extra_body`: `large_string` = `NULL`
- `api`: `large_string` = `NULL`
- `timeout_seconds`: `double` = `NULL`

**Examples**

```sql
SELECT openai_complete('Classify this card transaction memo into exactly one category from [groceries, dining, travel, utilities, other]. Reply with the category only, lowercase. Memo: UBER *TRIP SAN FRANCISCO CA', model => 'gpt-4o-mini', temperature => 0.0, max_tokens => 5).completion AS memo_category;
```

```text
travel
```

```sql
SELECT openai_complete('Rate the urgency of this support ticket from 1 (low) to 5 (critical) and name its topic in one word. Ticket: Our checkout page has returned 500 errors for every customer since 9am.', model => 'gpt-4o-mini', temperature => 0.0, response_format => '{"type": "json_schema", "json_schema": {"name": "ticket", "strict": true, "schema": {"type": "object", "properties": {"urgency": {"type": "integer"}, "topic": {"type": "string"}}, "required": ["urgency", "topic"], "additionalProperties": false}}}').completion AS ticket_triage;
```

```text
{"topic":"Checkout","urgency":5}
```

## `openai_complete_raw(prompt)`
source: https://docs.chalk.ai/chalksql-docs#openai_complete_raw

Makes a completion request to OpenAI's chat API and returns the raw JSON response string.

**Parameters**

- `prompt`: `large_string`
- `model`: `large_string` = `NULL`
- `api_server`: `large_string` = `NULL`
- `api_key`: `large_string` = `NULL`
- `max_tokens`: `int64` = `NULL`
- `temperature`: `double` = `NULL`
- `service_tier`: `large_string` = `NULL`
- `response_format`: `large_string` = `NULL`
- `chat_template_kwargs`: `large_string` = `NULL`

**Examples**

```sql
SELECT json_extract_scalar(openai_complete_raw('Classify this card transaction memo into one category (groceries, travel, dining, utilities). Reply with only the category: UBER *TRIP SAN FRANCISCO', model => 'gpt-4o-mini', temperature => 0.0), '$.choices[0].message.content') AS memo_category;
```

```text
travel
```

```sql
SELECT json_extract_scalar(openai_complete_raw('Summarize this support ticket in one sentence: My order #4821 arrived with a cracked screen and I need a replacement before Friday.', model => 'gpt-4o-mini', max_tokens => 5, temperature => 0.0), '$.choices[0].finish_reason') AS finish_reason;
```

```text
length
```

## `openai_embed(input)`
source: https://docs.chalk.ai/chalksql-docs#openai_embed

Makes an embedding request to OpenAI's embeddings API and returns the response.

**Parameters**

- `input`: `large_string`
  The `input` value.
- `model`: `large_string` = `NULL`
- `api_server`: `large_string` = `NULL`
- `api_key`: `large_string` = `NULL`
- `dimensions`: `int64` = `NULL`
  The embedding dimension count.

**Examples**

```sql
SELECT round(cosine_similarity_vector(openai_embed('Wireless noise-cancelling headphones', model => 'text-embedding-3-small').embedding, openai_embed('Bluetooth over-ear headset with ANC', model => 'text-embedding-3-small').embedding), 1) AS title_similarity;
```

```text
0.6
```

```sql
SELECT cardinality(openai_embed('Wireless noise-cancelling headphones', model => 'text-embedding-3-small', dimensions => 256).embedding) AS embedding_dims;
```

```text
256
```

## `prompt_jev(state, questions)`
source: https://docs.chalk.ai/chalksql-docs#prompt_jev

Asks Jev's structured-decision API a set of typed `questions` (noul/choice/score) about ``state`` and returns the answers as a JSON string alongside usage statistics.

**Parameters**

- `state`: `large_string`
  The current `state` value.
- `questions`: `large_string`
- `model`: `large_string` = `NULL`
- `api_server`: `large_string` = `NULL`
- `api_key`: `large_string` = `NULL`

## `sagemaker_predict(body)`
source: https://docs.chalk.ai/chalksql-docs#sagemaker_predict

Invokes an AWS SageMaker endpoint for inference with the provided binary input and returns the binary output.

**Parameters**

- `body`: `large_binary`
  The request `body`.
- `endpoint`: `large_string`
  The name of the model `endpoint` to invoke.
- `content_type`: `large_string`
  The request content type.
- `target_model`: `large_string`
- `target_variant`: `large_string`
- `aws_access_key_id_override`: `large_string`
- `aws_secret_access_key_override`: `large_string`
- `aws_session_token_override`: `large_string`
- `aws_role_arn_override`: `large_string`
- `aws_region_override`: `large_string`
- `aws_profile_name_override`: `large_string`
- `inference_component`: `large_string`

## `vertex_predict(body)`
source: https://docs.chalk.ai/chalksql-docs#vertex_predict

Invokes a Vertex AI endpoint for inference with binary input, returns binary output.

**Parameters**

- `body`: `large_binary`
  The request `body`.
- `endpoint`: `large_string`
  The name of the model `endpoint` to invoke.
- `content_type`: `large_string` = `NULL`
  The request content type.
- `gcp_credentials_override`: `large_string` = `NULL`
- `dedicated_endpoint_dns`: `large_string` = `NULL`
- `method`: `large_string` = `NULL`
  The HTTP `method`, such as 'GET' or 'POST'.
- `api_host`: `large_string` = `NULL`
