KosmoKrator

data

Cohere Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Cohere KosmoKrator integration.

Lua Namespace

Agents call this integration through app.integrations.cohere.*. Use lua_read_doc("integrations.cohere") inside KosmoKrator to discover the same reference at runtime.

Call Lua from the Headless CLI

Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic Cohere workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.cohere.chat({model = "example_model", messages = "example_messages", stream = true, tools = "example_tools", documents = "example_documents", citation_options = "example_citation_options", response_format = "example_response_format", safety_mode = "example_safety_mode"}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("cohere"))' --json
kosmo integrations:lua --eval 'print(docs.read("cohere.chat"))' --json

Workflow file

Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.

workflow.lua
local cohere = app.integrations.cohere
local result = cohere.chat({model = "example_model", messages = "example_messages", stream = true, tools = "example_tools", documents = "example_documents", citation_options = "example_citation_options", response_format = "example_response_format", safety_mode = "example_safety_mode"})

dump(result)
Run the workflow
kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json
Namespace note. integrations:lua exposes app.integrations.cohere, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.cohere.default.* or app.integrations.cohere.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need Cohere, use the narrower mcp:lua command.

MCP Lua command
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Cohere

Namespace: cohere

Cohere exposes AI models for chat, embeddings, reranking, tokenization, asynchronous embed jobs, datasets, audio transcription, and legacy classification.

Common Usage

Use cohere_chat for non-streaming v2 Chat responses. The tool always sends stream=false; SSE streaming is intentionally unsupported in this integration because the host tool runtime expects JSON responses.

local response = cohere.chat({
  model = "command-a-03-2025",
  messages = {
    { role = "user", content = "Summarize the launch notes in one paragraph." }
  },
  max_tokens = 300
})

Use cohere_embed for v2 embeddings. Set input_type to match the downstream use case:

  • search_document for indexed documents
  • search_query for user queries
  • classification for classifier features
  • clustering for clustering workflows
  • image for image inputs
local vectors = cohere.embed({
  model = "embed-v4.0",
  input_type = "search_document",
  texts = { "Shipping policy", "Refund policy" },
  embedding_types = { "float" }
})

Use cohere_rerank after retrieval to sort candidate documents by relevance.

local ranked = cohere.rerank({
  model = "rerank-v4.0-pro",
  query = "Where is billing history?",
  documents = {
    "Invoices are available in Account > Billing.",
    "API keys can be rotated in Settings."
  },
  top_n = 1
})

Datasets And Embed Jobs

Create a dataset with cohere_create_dataset, then start a batch embedding run with cohere_create_embed_job. For embed jobs, Cohere expects a validated dataset of type embed-input.

local dataset = cohere.create_dataset({
  name = "docs",
  type = "embed-input",
  filename = "docs.jsonl",
  content = "{\"text\":\"Billing docs\"}\n"
})

local job = cohere.create_embed_job({
  model = "embed-english-v3.0",
  dataset_id = dataset.id,
  input_type = "search_document"
})

Poll with cohere_get_embed_job; completed jobs expose output_dataset_id in the normalized Cohere response. cohere_cancel_embed_job cancels active jobs, but Cohere may still bill for work already processed and partial results are not returned.

Audio

cohere_create_audio_transcription sends multipart file content to v2 Audio Transcriptions. Provide the audio bytes through the host file-reading flow before calling the tool. Supported filename extensions include flac, mp3, mpeg, mpga, ogg, and wav.

Models And Tokens

cohere_list_models supports page_size, page_token, endpoint, and default_only. Use cohere_get_model to inspect endpoint compatibility, deprecation state, context length, features, and sampling defaults.

cohere_tokenize and cohere_detokenize use the tokenizer for the provided model.

Deprecated Classify

cohere_classify is exposed for compatibility, but Cohere marks v1 Classify as deprecated. Prefer chat or embedding-based classification for new workflows unless you are using an existing fine-tuned classify model.

Return Shapes

The integration returns Cohere’s JSON response shapes directly after successful calls. Common response fields include:

  • Chat: id, finish_reason, message, usage
  • Embed: embeddings, texts or image/mixed metadata, meta
  • Rerank: results, each with index and relevance_score
  • Models: models plus next_page_token, or a single model object
  • Datasets: datasets, dataset, id, or organization_usage
  • Embed jobs: job_id, status, input_dataset_id, output_dataset_id, meta
  • Audio transcription: text

All examples use fake or generic data and are safe to publish.

Raw agent markdown
# Cohere

Namespace: `cohere`

Cohere exposes AI models for chat, embeddings, reranking, tokenization, asynchronous embed jobs, datasets, audio transcription, and legacy classification.

## Common Usage

Use `cohere_chat` for non-streaming v2 Chat responses. The tool always sends `stream=false`; SSE streaming is intentionally unsupported in this integration because the host tool runtime expects JSON responses.

```lua
local response = cohere.chat({
  model = "command-a-03-2025",
  messages = {
    { role = "user", content = "Summarize the launch notes in one paragraph." }
  },
  max_tokens = 300
})
```

Use `cohere_embed` for v2 embeddings. Set `input_type` to match the downstream use case:

- `search_document` for indexed documents
- `search_query` for user queries
- `classification` for classifier features
- `clustering` for clustering workflows
- `image` for image inputs

```lua
local vectors = cohere.embed({
  model = "embed-v4.0",
  input_type = "search_document",
  texts = { "Shipping policy", "Refund policy" },
  embedding_types = { "float" }
})
```

Use `cohere_rerank` after retrieval to sort candidate documents by relevance.

```lua
local ranked = cohere.rerank({
  model = "rerank-v4.0-pro",
  query = "Where is billing history?",
  documents = {
    "Invoices are available in Account > Billing.",
    "API keys can be rotated in Settings."
  },
  top_n = 1
})
```

## Datasets And Embed Jobs

Create a dataset with `cohere_create_dataset`, then start a batch embedding run with `cohere_create_embed_job`. For embed jobs, Cohere expects a validated dataset of type `embed-input`.

```lua
local dataset = cohere.create_dataset({
  name = "docs",
  type = "embed-input",
  filename = "docs.jsonl",
  content = "{\"text\":\"Billing docs\"}\n"
})

local job = cohere.create_embed_job({
  model = "embed-english-v3.0",
  dataset_id = dataset.id,
  input_type = "search_document"
})
```

Poll with `cohere_get_embed_job`; completed jobs expose `output_dataset_id` in the normalized Cohere response. `cohere_cancel_embed_job` cancels active jobs, but Cohere may still bill for work already processed and partial results are not returned.

## Audio

`cohere_create_audio_transcription` sends multipart file content to v2 Audio Transcriptions. Provide the audio bytes through the host file-reading flow before calling the tool. Supported filename extensions include `flac`, `mp3`, `mpeg`, `mpga`, `ogg`, and `wav`.

## Models And Tokens

`cohere_list_models` supports `page_size`, `page_token`, `endpoint`, and `default_only`. Use `cohere_get_model` to inspect endpoint compatibility, deprecation state, context length, features, and sampling defaults.

`cohere_tokenize` and `cohere_detokenize` use the tokenizer for the provided model.

## Deprecated Classify

`cohere_classify` is exposed for compatibility, but Cohere marks v1 Classify as deprecated. Prefer chat or embedding-based classification for new workflows unless you are using an existing fine-tuned classify model.

## Return Shapes

The integration returns Cohere's JSON response shapes directly after successful calls. Common response fields include:

- Chat: `id`, `finish_reason`, `message`, `usage`
- Embed: `embeddings`, `texts` or image/mixed metadata, `meta`
- Rerank: `results`, each with `index` and `relevance_score`
- Models: `models` plus `next_page_token`, or a single model object
- Datasets: `datasets`, `dataset`, `id`, or `organization_usage`
- Embed jobs: `job_id`, `status`, `input_dataset_id`, `output_dataset_id`, `meta`
- Audio transcription: `text`

All examples use fake or generic data and are safe to publish.
Metadata-derived Lua example
local result = app.integrations.cohere.chat({model = "example_model", messages = "example_messages", stream = true, tools = "example_tools", documents = "example_documents", citation_options = "example_citation_options", response_format = "example_response_format", safety_mode = "example_safety_mode"})
print(result)

Functions

chat Read

Generate a non-streaming response with Cohere v2 Chat. Supports messages, documents, tools, citations, JSON response format, safety mode, sampling controls, and reasoning configuration.

Lua path
app.integrations.cohere.chat
Full name
cohere.cohere_chat
ParameterTypeRequiredDescription
model string yes Cohere chat model ID, for example command-a-03-2025.
messages array yes Chronological chat messages with user, assistant, system, or tool roles.
stream boolean no Must be false or omitted. Streaming SSE is not supported by this tool.
tools array no Tool/function definitions available to the model.
documents array no Relevant documents as strings or objects for citation-aware generation.
citation_options object no Citation generation options.
response_format object no Response format control, such as json_object with optional JSON schema.
safety_mode string no Safety instruction mode for compatible models.
max_tokens integer no Maximum output tokens.
stop_sequences array no Up to five stop strings.
temperature number no Sampling temperature.
seed integer no Best-effort deterministic seed.
frequency_penalty number no Penalty for repeated token frequency.
presence_penalty number no Penalty for already-present tokens.
k integer no Top-k sampling control.
p number no Top-p sampling control.
logprobs boolean no Include token log probabilities when supported.
tool_choice string no Force tool use or direct response for compatible models.
thinking object no Reasoning feature configuration for supported models.
priority integer no Priority from 0 to 999, where lower values are handled earlier.
strict_tools boolean no Force tool calls to follow the supplied tool schema strictly.
embed Read

Create Cohere v2 embeddings for texts, image data URIs, or mixed inputs. Use input_type to match the downstream task such as search_document, search_query, classification, clustering, or image.

Lua path
app.integrations.cohere.embed
Full name
cohere.cohere_embed
ParameterTypeRequiredDescription
model string yes Embedding model ID.
input_type string yes Embedding input type.
texts array no Text inputs to embed. Maximum 96 per call.
images array no Image data URI inputs. Maximum 1 image per call.
inputs array no Mixed text/image component inputs. Maximum 96 per call.
max_tokens integer no Maximum tokens to embed per input.
output_dimension integer no Output embedding dimension for embed-v4 and newer models.
embedding_types array no Embedding formats such as float, int8, uint8, binary, or ubinary.
truncate string no How to truncate inputs that exceed context.
priority integer no Priority from 0 to 999, where lower values are handled earlier.
rerank Read

Rerank a list of documents for a search query using Cohere v2 Rerank. Documents may be strings; structured data should be converted to YAML strings before calling.

Lua path
app.integrations.cohere.rerank
Full name
cohere.cohere_rerank
ParameterTypeRequiredDescription
model string yes Rerank model ID, for example rerank-v4.0-pro.
query string yes Search query.
documents array yes Documents to compare to the query. Cohere recommends no more than 1000 per call.
top_n integer no Maximum number of ranked results to return.
max_tokens_per_doc integer no Token truncation limit per document. Defaults to 4096 upstream.
priority integer no Priority from 0 to 999, where lower values are handled earlier.
tokenize Read

Tokenize text with the tokenizer used by a Cohere model. Use this before budgeting prompts or debugging token boundaries.

Lua path
app.integrations.cohere.tokenize
Full name
cohere.cohere_tokenize
ParameterTypeRequiredDescription
text string yes Text to tokenize.
model string yes Model whose tokenizer should be used.
detokenize Read

Convert Cohere model token IDs back to text with the tokenizer used by a specific model.

Lua path
app.integrations.cohere.detokenize
Full name
cohere.cohere_detokenize
ParameterTypeRequiredDescription
tokens array yes Token integer IDs to detokenize.
model string yes Model whose tokenizer should be used.
list_models Read

List Cohere models with optional pagination and endpoint/default filters.

Lua path
app.integrations.cohere.list_models
Full name
cohere.cohere_list_models
ParameterTypeRequiredDescription
page_size number no Maximum models per page. Range: 1-1000. Default: 20.
page_token string no Token from next_page_token in a previous response.
endpoint string no Only return models compatible with this endpoint.
default_only boolean no Only return default models for the endpoint. Valid only when endpoint is provided.
get_model Read

Get Cohere model metadata including compatible endpoints, deprecation state, context length, features, and sampling defaults.

Lua path
app.integrations.cohere.get_model
Full name
cohere.cohere_get_model
ParameterTypeRequiredDescription
model string yes Model name to retrieve.
create_embed_job Write

Start a Cohere embed job for a validated embed-input dataset. Use list/get embed job to track completion and read output_dataset_id.

Lua path
app.integrations.cohere.create_embed_job
Full name
cohere.cohere_create_embed_job
ParameterTypeRequiredDescription
model string yes Embedding model ID.
dataset_id string yes Validated embed-input dataset ID.
input_type string yes Embedding input type.
truncate string no How to truncate text that exceeds model limits.
name string no Optional embed job display name.
list_embed_jobs Read

List Cohere embed jobs for the authenticated user.

Lua path
app.integrations.cohere.list_embed_jobs
Full name
cohere.cohere_list_embed_jobs
ParameterTypeRequiredDescription
No parameters.
get_embed_job Read

Get details for a Cohere embed job, including status and output_dataset_id when complete.

Lua path
app.integrations.cohere.get_embed_job
Full name
cohere.cohere_get_embed_job
ParameterTypeRequiredDescription
job_id string yes Embed job ID.
cancel_embed_job Write

Cancel an active Cohere embed job. Cohere may bill for work already processed, and partial results are not returned.

Lua path
app.integrations.cohere.cancel_embed_job
Full name
cohere.cohere_cancel_embed_job
ParameterTypeRequiredDescription
job_id string yes Embed job ID to cancel.
create_dataset Write

Upload a dataset file to Cohere. For embed jobs, use type=embed-input and a JSONL/CSV/TXT file that matches Cohere dataset rules.

Lua path
app.integrations.cohere.create_dataset
Full name
cohere.cohere_create_dataset
ParameterTypeRequiredDescription
name string yes Dataset display name.
type string yes Dataset type, for example embed-input.
filename string yes Filename for the uploaded dataset.
content string yes Raw dataset file content.
eval_filename string no Optional evaluation filename.
eval_content string no Optional evaluation file content.
keep_original_file boolean no Store the original uploaded file.
skip_malformed_input boolean no Drop malformed rows instead of failing validation.
keep_fields array no Required fields to preserve.
optional_fields array no Optional fields to preserve.
text_separator string no Separator for raw text uploads.
csv_delimiter string no Delimiter for CSV uploads.
list_datasets Read

List Cohere datasets with optional datasetType, before, after, limit, and offset filters.

Lua path
app.integrations.cohere.list_datasets
Full name
cohere.cohere_list_datasets
ParameterTypeRequiredDescription
datasetType string no Optional dataset type filter. Use Cohere casing: datasetType.
before string no Return datasets before this ISO date-time.
after string no Return datasets after this ISO date-time.
limit number no Maximum number of results.
offset number no Offset into the result set.
get_dataset Read

Get a Cohere dataset by ID, including validation status, schema, dataset parts, and metrics.

Lua path
app.integrations.cohere.get_dataset
Full name
cohere.cohere_get_dataset
ParameterTypeRequiredDescription
dataset_id string yes Dataset ID.
delete_dataset Write

Delete a Cohere dataset by ID. Cohere also automatically expires datasets after its retention period.

Lua path
app.integrations.cohere.delete_dataset
Full name
cohere.cohere_delete_dataset
ParameterTypeRequiredDescription
dataset_id string yes Dataset ID to delete.
get_dataset_usage Read

Get Cohere organization dataset storage usage in bytes.

Lua path
app.integrations.cohere.get_dataset_usage
Full name
cohere.cohere_get_dataset_usage
ParameterTypeRequiredDescription
No parameters.
create_audio_transcription Read

Transcribe an audio file with Cohere v2 Audio Transcriptions. Provide file content directly; supported extensions include flac, mp3, mpeg, mpga, ogg, and wav.

Lua path
app.integrations.cohere.create_audio_transcription
Full name
cohere.cohere_create_audio_transcription
ParameterTypeRequiredDescription
filename string yes Audio filename including extension.
content string yes Raw audio file bytes as a string from the host.
model string yes Transcription model ID, for example cohere-transcribe-03-2026.
language string yes ISO-639-1 language code, for example en.
temperature number no Optional sampling temperature between 0 and 1.
classify Read

Classify text with Cohere v1 Classify. Upstream marks this endpoint deprecated; prefer newer chat or embedding workflows unless you need legacy classify compatibility.

Lua path
app.integrations.cohere.classify
Full name
cohere.cohere_classify
ParameterTypeRequiredDescription
inputs array yes Texts to classify. Maximum 96.
examples array no Optional examples as objects with text and label. Not required for fine-tuned classify models.
model string no Optional fine-tuned Classify model ID.
truncate string no How to handle inputs longer than model limits.
preset string no Deprecated upstream preset parameter.