Skip to content
Proud to collaborate with Microsoft for Startups

ai.chat.complete ​

OpenAI-compatible chat completion (any provider), with optional provider web search and citations

Send a chat completion request to any OpenAI-compatible API.

Works with OpenAI, Anthropic (via openai-compat endpoint), AWS Bedrock proxy, Ollama, Together AI, Groq, and any provider that implements the /chat/completions endpoint.

Inputs:

  • messages: List of {role, content} objects (required). Roles: user, assistant, system.
  • model: Model ID override (optional, default: plugin.default_model).
  • system_prompt: System instruction prepended as a system message (optional).
  • temperature: Sampling temperature 0.0–2.0 (optional).
  • max_tokens: Maximum tokens to generate (optional, default: 1024).
  • attachment_uuids: List of StorageObject UUIDs to include as multimodal image content in the last user message (optional). Only image/* content types are supported in this version; non-image attachments are silently dropped when text is also present, or cause a WorkflowNotRetryableError when there is no accompanying text.
  • web_search: Optional object. When {"enabled": true}, the answer is produced WITH the provider's own web search and normalized citations are returned. Absent (or enabled not true) = the unchanged Chat Completions behavior. Keys: enabled (bool), force (bool: require a search where the provider documents it), max_uses (int), user_location ({country, region, city, timezone}), allowed_domains / blocked_domains (lists; not both). The provider comes from the connection's API host: api.openai.com -> Responses API POST /v1/responses (web_search tool) api.anthropic.com -> Messages API POST /v1/messages (web_search_20250305) api.perplexity.ai -> Agent API POST /v1/agent (web_search tool) api.x.ai -> Responses API POST /v1/responses (web_search tool) *.openai.azure.com, *.services.ai.azure.com, *.cognitiveservices.azure.com -> Azure OpenAI v1 Responses API POST <base_url>/responses (web_search tool; base_url must be the /openai/v1 surface; api-key header, or Bearer when the stored credential is an Entra JWT) Any other host (Gemini/Google, OpenRouter, MiniMax, gateways) fails with web_search_unsupported_provider rather than answering without search. Options a provider cannot honor are listed in web_search_notes (e.g. xAI rejects user_location, so it is never sent). Cannot be combined with stream_to_workflow_id, tools, tool_choice, parallel_tool_calls, response_format or attachment_uuids.

Outputs (terminal state_data):

  • content: str — assistant reply text
  • role: str — always "assistant"
  • finish_reason: str — stop | length | tool_calls | etc.
  • model: str — model ID used
  • input_tokens: int — prompt token count
  • output_tokens: int — completion token count Only when web_search is enabled:
  • citations: list of {url, title, domain, start_index, end_index, cited_text}; indices are character offsets into content, null when the provider gives no span
  • web_search_performed: bool — read from the provider response, never assumed
  • web_search_queries: list[str] — queries the provider reports it ran
  • web_search_count: int — searches the provider reports (billed search calls)
  • web_search_notes: list[str] — options not applied, search errors, citation provenance
  • web_search_provider: str — openai | anthropic | perplexity | xai | azure_openai

Failure reasons added by web_search (failure_reason starts with one of): web_search_invalid_input, web_search_incompatible_input, web_search_streaming_unsupported, web_search_unsupported_provider, web_search_upstream_auth_failed, web_search_upstream_error, web_search_invalid_response

Plugin required: context.get_plugin("ai") must expose:

  • .api_url — base URL, e.g. https://api.openai.com/v1
  • .api_key — bearer token
  • .default_model — fallback model ID

Overview ​

PropertyValue
Workflow typeAtomic
LibraryApp-ai
Version1.0

Input Schema ​

FieldTypeRequiredDefaultDescription
messagesjsonYes—List of {role, content} message objects
modelstringNo—Model ID (default: plugin.default_model)
system_promptstringNo—System instruction (prepended as system message)
temperaturejsonNo—Sampling temperature 0.0–2.0
max_tokensintegerNo—Max tokens to generate (default: 1024)
attachment_uuidsjsonNo—List of StorageObject UUIDs for multimodal image content
toolsjsonNo—OpenAI-compatible tool definitions
tool_choicejsonNo—OpenAI-compatible tool_choice
parallel_tool_callsbooleanNo—Whether the provider may return multiple tool calls
response_formatjsonNo—OpenAI-compatible response_format
timeout_secondsintegerNo—Provider HTTP timeout in seconds
connection_uuiduuidNo—Explicit AI CloudConnection UUID — resolved + decrypted directly (org-context-free, highest precedence). Mirrors ai.chat; lets async-DAG/consumer callers pass the org's connection without org context in context.metadata.
ai_provider_config_uuiduuidNo—Explicit AIProviderConfig UUID — resolved to its connection (second precedence, after connection_uuid).
stream_to_workflow_idstringNo—When set, stream this completion (provider stream=True) and publish each content delta as a token frame to Redis channel dgi:tokens:<id>, so a live SSE consumer (GET /api/workflows/<id>/stream) can render tokens as they generate. The full message (content + tool_calls) is still reconstructed and returned unchanged, so the agent loop is unaffected. Absent = the existing synchronous behavior (zero change for every non-streaming caller).
organization_uuiduuidNo—Ignored when present — the organization is resolved from the authenticated context. Accepted so callers that inject it unconditionally (the agents tool runtime injects it into every workflow-skill call) do not fail input validation.
web_searchjsonNo—Optional {enabled, force, max_uses, user_location: {country, region, city, timezone}, allowed_domains, blocked_domains}. When enabled is true the provider answers with its own web search (OpenAI, Anthropic, Perplexity, xAI, Azure OpenAI; chosen by the connection's API host) and citations are returned. Any other provider fails with web_search_unsupported_provider. Absent = unchanged Chat Completions behavior.

Output Schema ​

FieldTypeRequiredDefaultDescription
contentstringNo——
rolestringNo——
messagejsonNo——
tool_callsjsonNo——
finish_reasonstringNo——
modelstringNo——
provider_response_idstringNo——
input_tokensintegerNo——
output_tokensintegerNo——
total_tokensintegerNo——
usagejsonNo——
citationsjsonNo—List of
web_search_performedbooleanNo—Whether the provider reports it searched (read from the response)
web_search_queriesjsonNo—Search queries the provider reports it ran
web_search_countintegerNo—Number of searches the provider reports
web_search_notesjsonNo—Options the provider could not honor, search errors, citation provenance
web_search_providerstringNo—openai
failure_reasonstringNo——
failure_typestringNo——
failed_actionstringNo——
failed_at_statestringNo——
errorstringNo——
error_typestringNo——
failed_stepstringNo——
failed_layerjsonNo——
failed_atstringNo——

States ​

StateInitialTerminalSuccessAuto-advanceDescription
pendingYesNo—execute—
completedNoYesYes——
failedNoYesNo——

State Diagram ​

Transitions ​

FromActionToDescription
pendingexecutecompleted—
* (any state)failfailed—

API Usage ​

bash
POST /api/workflows/start
Content-Type: application/json

{
  "workflow_type": "ai.chat.complete",
  "initial_data": {
    "messages": "value"
  }
}