Samples
Basic chat
Chat with documents (RAG)
Use tools
Arguments
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
model | TEXT | - | ✔ | Cohere model (e.g., command-r-plus, command-r) |
messages | JSONB | - | ✔ | Array of message objects with role and content |
api_key | TEXT | NULL | ✖ | Cohere API key |
api_key_name | TEXT | NULL | ✖ | Name of secret containing the API key |
tools | JSONB | NULL | ✖ | Tool definitions for function calling |
documents | JSONB | NULL | ✖ | Documents for RAG |
citation_options | JSONB | NULL | ✖ | Citation configuration |
response_format | JSONB | NULL | ✖ | Response format specification |
safety_mode | TEXT | NULL | ✖ | Safety mode setting |
max_tokens | INT | NULL | ✖ | Maximum tokens to generate |
stop_sequences | TEXT[] | NULL | ✖ | Sequences that stop generation |
temperature | FLOAT8 | NULL | ✖ | Sampling temperature (0.0 to 1.0) |
seed | INT | NULL | ✖ | Random seed for reproducibility |
frequency_penalty | FLOAT8 | NULL | ✖ | Frequency penalty |
presence_penalty | FLOAT8 | NULL | ✖ | Presence penalty |
k | INT | NULL | ✖ | Top-k sampling parameter |
p | FLOAT8 | NULL | ✖ | Top-p (nucleus) sampling parameter |
logprobs | BOOLEAN | NULL | ✖ | Return log probabilities |
tool_choice | TEXT | NULL | ✖ | Tool choice strategy |
strict_tools | BOOL | NULL | ✖ | Enforce strict tool schemas |
verbose | BOOLEAN | FALSE | ✖ | Enable verbose logging |
Returns
JSONB: Complete API response with message, citations, and metadata.
Related functions
cohere_rerank(): rerank documents for RAGanthropic_generate(): alternative with Claude models