{"command":{"effect":"write","timeoutSeconds":30,"inputSchema":{"type":"object","description":"Performs a chat completion request against multiple AI Search instances in parallel, merging retrieved content as context for generating a response.","properties":{"path":{"type":"object","properties":{"account_id":{"type":"string","examples":["c3dc5f0b34a14ff8e1b3ec04895e1b22"]},"name":{"type":"string","examples":["my-namespace"],"description":"Namespace name."}},"required":["account_id","name"],"additionalProperties":false},"body":{"type":"object","properties":{"ai_search_options":{"type":"object","properties":{"cache":{"type":"object","properties":{"cache_threshold":{"type":"string","enum":["super_strict_match","close_enough","flexible_friend","anything_goes"]},"enabled":{"type":"boolean"}}},"custom_metadata":{"description":"Metadata added to AI Gateway logs for requests this operation triggers. Accepts up to 2 string, number, or boolean entries. Reserved keys: 'ai-search', 'task', 'origin', and any key beginning with 'cf.'.","type":"object","additionalProperties":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"}]},"maxProperties":2,"examples":[{"test":true,"user_id":"user-123"}]},"instance_ids":{"type":"array","items":{"description":"AI Search instance ID. Lowercase alphanumeric, hyphens, and underscores.","maxLength":64,"minLength":1,"pattern":"^[a-z0-9_]+(?:-[a-z0-9_]+)*$","type":"string","examples":["my-ai-search"]},"minItems":1},"query_rewrite":{"type":"object","properties":{"enabled":{"type":"boolean"},"model":{"description":"A Workers AI model ID or an AI Gateway model ID compatible with the OpenAI Chat Completions API. An empty string uses the configured or default model.","type":"string"},"rewrite_prompt":{"type":"string"}}},"reranking":{"type":"object","properties":{"enabled":{"type":"boolean"},"match_threshold":{"type":"number","default":0.4,"maximum":1,"minimum":0},"model":{"type":"string"}}},"retrieval":{"type":"object","properties":{"boost_by":{"description":"Metadata fields to boost search results by. Overrides the instance-level boost_by config. Direction defaults to 'asc' for numeric/datetime fields, 'exists' for text/boolean fields. Fields must match 'timestamp' or a defined custom_metadata field.","type":"array","items":{"properties":{"direction":{"description":"Boost direction. 'desc' = higher values rank higher (e.g. newer timestamps). 'asc' = lower values rank higher. 'exists' = boost chunks that have the field. 'not_exists' = boost chunks that lack the field. Optional — defaults to 'asc' for numeric/datetime fields, 'exists' for text/boolean fields.","type":"string","enum":["asc","desc","exists","not_exists"]},"field":{"description":"Metadata field name to boost by. Use 'timestamp' for document freshness, or any custom_metadata field. Numeric and datetime fields support all four directions (asc, desc, exists, not_exists); text/boolean fields only support exists/not_exists.","type":"string","maxLength":64,"minLength":1,"examples":["timestamp"]}},"required":["field"],"type":"object"},"maxItems":3,"examples":[[{"direction":"desc","field":"timestamp"}]]},"context_expansion":{"type":"integer","default":0,"maximum":3,"minimum":0},"filters":{"type":"object","additionalProperties":true},"fusion_method":{"type":"string","enum":["max","rrf"]},"keyword_match_mode":{"description":"Controls which documents become candidates for BM25 scoring. 'and' restricts candidates to documents containing all query terms; 'or' includes any document containing at least one term and ranks results according to BM25 relevance. When omitted, falls back to the instance-level retrieval_options.keyword_match_mode, then to 'and'.","type":"string","enum":["and","or"]},"match_threshold":{"description":"Minimum score a chunk must reach to be returned. When omitted, each instance's chunks are filtered by that instance's score_threshold, capped at the lower of the first instance's score_threshold and 0.4.","type":"number","maximum":1,"minimum":0},"max_num_results":{"description":"Maximum number of merged results to return. When omitted, defaults to the first instance's max_num_results, then 10.","type":"integer","maximum":50,"minimum":1},"retrieval_type":{"type":"string","enum":["vector","keyword","hybrid"]},"return_on_failure":{"type":"boolean","default":true}}}},"required":["instance_ids"]},"messages":{"type":"array","items":{"additionalProperties":true,"properties":{"content":{"anyOf":[{"type":"string"},{"items":{"oneOf":[{"properties":{"text":{"type":"string","minLength":1},"type":{"type":"string","enum":["text"]}},"required":["type","text"],"type":"object"},{"properties":{"image_url":{"type":"object","properties":{"url":{"type":"string","maxLength":20971520,"minLength":1}},"required":["url"]},"type":{"type":"string","enum":["image_url"]}},"required":["type","image_url"],"type":"object"},{"properties":{"file":{"type":"object","properties":{"file_data":{"type":"string","maxLength":13981144,"minLength":1},"file_id":{"type":"string"},"filename":{"type":"string","maxLength":255,"minLength":1}},"required":["filename"]},"type":{"type":"string","enum":["file"]}},"required":["type","file"],"type":"object"}]},"minItems":1,"type":"array"},{"enum":[null],"type":["string","null"]}]},"role":{"type":"string","enum":["system","developer","user","assistant","tool"]}},"required":["role","content"],"type":"object"},"minItems":1},"model":{"description":"A Workers AI model ID or an AI Gateway model ID compatible with the OpenAI Chat Completions API. An empty string uses the configured or default model.","type":"string"},"stream":{"type":"boolean"}},"additionalProperties":true,"required":["messages","ai_search_options"]}},"required":["path"],"additionalProperties":false},"name":"Multi-Instance Chat Completions","id":"cloudflare.ai-search-namespace-multi-instance-chat-completion","example":{"path":{"account_id":"c3dc5f0b34a14ff8e1b3ec04895e1b22","name":"my-namespace"}},"maxRequests":1,"summary":false}}