// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../core/resource'; import * as InstancesAPI from './instances/instances'; import { BaseInstances, InstanceChatCompletionsParams, InstanceChatCompletionsResponse, InstanceCreateParams, InstanceCreateResponse, InstanceDeleteParams, InstanceDeleteResponse, InstanceListParams, InstanceListResponse, InstanceListResponsesV4PagePaginationArray, InstanceReadParams, InstanceReadResponse, InstanceSearchParams, InstanceSearchResponse, InstanceStatsParams, InstanceStatsResponse, InstanceUpdateParams, InstanceUpdateResponse, Instances, } from './instances/instances'; import { APIPromise } from '../../../core/api-promise'; import { PagePromise, V4PagePaginationArray, type V4PagePaginationArrayParams, } from '../../../core/pagination'; import { RequestOptions } from '../../../internal/request-options'; import { path } from '../../../internal/utils/path'; export class BaseNamespaces extends APIResource { static override readonly _key: readonly ['aiSearch', 'namespaces'] = Object.freeze([ 'aiSearch', 'namespaces', ] as const); /** * Create a namespace for organizing AI Search instances. * * @example * ```ts * const namespace = await client.aiSearch.namespaces.create({ * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * name: 'name', * }); * ``` */ create(params: NamespaceCreateParams, options?: RequestOptions): APIPromise { const { account_id, ...body } = params; return ( this._client.post(path`/accounts/${account_id}/ai-search/namespaces`, { body, ...options, }) as APIPromise<{ result: NamespaceCreateResponse }> )._thenUnwrap((obj) => obj.result); } /** * Update the description and/or the public endpoint configuration of an existing * namespace. The default namespace's description cannot be modified, but its * public endpoint can. * * @example * ```ts * const namespace = await client.aiSearch.namespaces.update( * 'production', * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * ); * ``` */ update( name: string, params: NamespaceUpdateParams, options?: RequestOptions, ): APIPromise { const { account_id, ...body } = params; return ( this._client.put(path`/accounts/${account_id}/ai-search/namespaces/${name}`, { body, ...options, }) as APIPromise<{ result: NamespaceUpdateResponse }> )._thenUnwrap((obj) => obj.result); } /** * List namespaces in the account, including their descriptions and creation times. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const namespaceListResponse of client.aiSearch.namespaces.list( * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * )) { * // ... * } * ``` */ list( params: NamespaceListParams, options?: RequestOptions, ): PagePromise { const { account_id, ...query } = params; return this._client.getAPIList( path`/accounts/${account_id}/ai-search/namespaces`, V4PagePaginationArray, { query, ...options }, ); } /** * Permanently delete a namespace. The namespace must be empty (no instances), and * the default namespace cannot be deleted. * * @example * ```ts * const namespace = await client.aiSearch.namespaces.delete( * 'production', * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * ); * ``` */ delete( name: string, params: NamespaceDeleteParams, options?: RequestOptions, ): APIPromise { const { account_id } = params; return ( this._client.delete(path`/accounts/${account_id}/ai-search/namespaces/${name}`, options) as APIPromise<{ result: NamespaceDeleteResponse; }> )._thenUnwrap((obj) => obj.result); } /** * Performs a chat completion request against multiple AI Search instances in * parallel, merging retrieved content as context for generating a response. * * @example * ```ts * const response = * await client.aiSearch.namespaces.chatCompletions( * 'my-namespace', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * ai_search_options: { instance_ids: ['my-ai-search'] }, * messages: [{ content: 'string', role: 'system' }], * }, * ); * ``` */ chatCompletions( name: string, params: NamespaceChatCompletionsParams, options?: RequestOptions, ): APIPromise { const { account_id, ...body } = params; return this._client.post(path`/accounts/${account_id}/ai-search/namespaces/${name}/chat/completions`, { body, ...options, }); } /** * Retrieve a namespace and its description. * * @example * ```ts * const response = await client.aiSearch.namespaces.read( * 'production', * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * ); * ``` */ read( name: string, params: NamespaceReadParams, options?: RequestOptions, ): APIPromise { const { account_id } = params; return ( this._client.get(path`/accounts/${account_id}/ai-search/namespaces/${name}`, options) as APIPromise<{ result: NamespaceReadResponse; }> )._thenUnwrap((obj) => obj.result); } /** * Performs a semantic search query against multiple AI Search instances in * parallel, merging the retrieved results into a single ranked response. * * @example * ```ts * const response = await client.aiSearch.namespaces.search( * 'my-namespace', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * ai_search_options: { instance_ids: ['my-ai-search'] }, * }, * ); * ``` */ search( name: string, params: NamespaceSearchParams, options?: RequestOptions, ): APIPromise { const { account_id, ...body } = params; return ( this._client.post(path`/accounts/${account_id}/ai-search/namespaces/${name}/search`, { body, ...options, }) as APIPromise<{ result: NamespaceSearchResponse }> )._thenUnwrap((obj) => obj.result); } } export class Namespaces extends BaseNamespaces { instances: InstancesAPI.Instances = new InstancesAPI.Instances(this._client); } export type NamespaceListResponsesV4PagePaginationArray = V4PagePaginationArray; export interface NamespaceCreateResponse { created_at: string; name: string; /** * Optional description for the namespace. Max 256 characters. */ description?: string | null; public_endpoint_id?: string | null; public_endpoint_params?: NamespaceCreateResponse.PublicEndpointParams | null; } export namespace NamespaceCreateResponse { export interface PublicEndpointParams { authorized_hosts?: Array; chat_completions_endpoint?: PublicEndpointParams.ChatCompletionsEndpoint; /** * Custom domain hostnames that alias this public endpoint. GET and create * responses return the current set; on update (PUT) this field is only echoed back * when supplied in the request body, otherwise it is null (omit it to leave * domains unchanged). */ custom_domains?: Array | null; /** * When false, the instance is reachable only via a registered custom domain and * the default .search.ai.cloudflare.com host returns 404. * Requires at least one custom domain. Defaults to true. public_endpoint_params is * replaced wholesale on update, so resend default_domain_enabled on every update * to keep the default host off — omitting it resets to true. */ default_domain_enabled?: boolean; enabled?: boolean; /** * Instance IDs exposed through the namespace public endpoint. Empty means nothing * is searchable. Every ID must be an existing instance in this namespace, and the * list cannot exceed the account's multi-instance search limit. */ instances_allowed?: Array; mcp?: PublicEndpointParams.Mcp; rate_limit?: PublicEndpointParams.RateLimit; search_endpoint?: PublicEndpointParams.SearchEndpoint; } export namespace PublicEndpointParams { export interface ChatCompletionsEndpoint { /** * Disable chat completions endpoint for this public endpoint */ disabled?: boolean; } export interface Mcp { description?: string; /** * Disable MCP endpoint for this public endpoint */ disabled?: boolean; } export interface RateLimit { period_ms?: number; requests?: number; technique?: 'fixed' | 'sliding'; } export interface SearchEndpoint { /** * Disable search endpoint for this public endpoint */ disabled?: boolean; } } } export interface NamespaceUpdateResponse { created_at: string; name: string; /** * Optional description for the namespace. Max 256 characters. */ description?: string | null; public_endpoint_id?: string | null; public_endpoint_params?: NamespaceUpdateResponse.PublicEndpointParams | null; } export namespace NamespaceUpdateResponse { export interface PublicEndpointParams { authorized_hosts?: Array; chat_completions_endpoint?: PublicEndpointParams.ChatCompletionsEndpoint; /** * Custom domain hostnames that alias this public endpoint. GET and create * responses return the current set; on update (PUT) this field is only echoed back * when supplied in the request body, otherwise it is null (omit it to leave * domains unchanged). */ custom_domains?: Array | null; /** * When false, the instance is reachable only via a registered custom domain and * the default .search.ai.cloudflare.com host returns 404. * Requires at least one custom domain. Defaults to true. public_endpoint_params is * replaced wholesale on update, so resend default_domain_enabled on every update * to keep the default host off — omitting it resets to true. */ default_domain_enabled?: boolean; enabled?: boolean; /** * Instance IDs exposed through the namespace public endpoint. Empty means nothing * is searchable. Every ID must be an existing instance in this namespace, and the * list cannot exceed the account's multi-instance search limit. */ instances_allowed?: Array; mcp?: PublicEndpointParams.Mcp; rate_limit?: PublicEndpointParams.RateLimit; search_endpoint?: PublicEndpointParams.SearchEndpoint; } export namespace PublicEndpointParams { export interface ChatCompletionsEndpoint { /** * Disable chat completions endpoint for this public endpoint */ disabled?: boolean; } export interface Mcp { description?: string; /** * Disable MCP endpoint for this public endpoint */ disabled?: boolean; } export interface RateLimit { period_ms?: number; requests?: number; technique?: 'fixed' | 'sliding'; } export interface SearchEndpoint { /** * Disable search endpoint for this public endpoint */ disabled?: boolean; } } } export interface NamespaceListResponse { created_at: string; name: string; /** * Optional description for the namespace. Max 256 characters. */ description?: string | null; public_endpoint_id?: string | null; public_endpoint_params?: NamespaceListResponse.PublicEndpointParams | null; } export namespace NamespaceListResponse { export interface PublicEndpointParams { authorized_hosts?: Array; chat_completions_endpoint?: PublicEndpointParams.ChatCompletionsEndpoint; /** * Custom domain hostnames that alias this public endpoint. GET and create * responses return the current set; on update (PUT) this field is only echoed back * when supplied in the request body, otherwise it is null (omit it to leave * domains unchanged). */ custom_domains?: Array | null; /** * When false, the instance is reachable only via a registered custom domain and * the default .search.ai.cloudflare.com host returns 404. * Requires at least one custom domain. Defaults to true. public_endpoint_params is * replaced wholesale on update, so resend default_domain_enabled on every update * to keep the default host off — omitting it resets to true. */ default_domain_enabled?: boolean; enabled?: boolean; /** * Instance IDs exposed through the namespace public endpoint. Empty means nothing * is searchable. Every ID must be an existing instance in this namespace, and the * list cannot exceed the account's multi-instance search limit. */ instances_allowed?: Array; mcp?: PublicEndpointParams.Mcp; rate_limit?: PublicEndpointParams.RateLimit; search_endpoint?: PublicEndpointParams.SearchEndpoint; } export namespace PublicEndpointParams { export interface ChatCompletionsEndpoint { /** * Disable chat completions endpoint for this public endpoint */ disabled?: boolean; } export interface Mcp { description?: string; /** * Disable MCP endpoint for this public endpoint */ disabled?: boolean; } export interface RateLimit { period_ms?: number; requests?: number; technique?: 'fixed' | 'sliding'; } export interface SearchEndpoint { /** * Disable search endpoint for this public endpoint */ disabled?: boolean; } } } export type NamespaceDeleteResponse = unknown; export interface NamespaceChatCompletionsResponse { choices: Array; chunks: Array; id?: string; errors?: Array; model?: string; object?: string; [k: string]: unknown; } export namespace NamespaceChatCompletionsResponse { export interface Choice { message: Choice.Message; index?: number; } export namespace Choice { export interface Message { content: string | Array | null; role: 'system' | 'developer' | 'user' | 'assistant' | 'tool'; [k: string]: unknown; } export namespace Message { export interface UnionMember0 { text: string; type: 'text'; } export interface UnionMember1 { image_url: UnionMember1.ImageURL; type: 'image_url'; } export namespace UnionMember1 { export interface ImageURL { url: string; } } export interface UnionMember2 { file: UnionMember2.File; type: 'file'; } export namespace UnionMember2 { export interface File { filename: string; file_data?: string; file_id?: string; } } } } export interface Chunk { id: string; instance_id: string; score: number; text: string; type: string; item?: Chunk.Item; scoring_details?: Chunk.ScoringDetails; } export namespace Chunk { export interface Item { key: string; metadata?: { [key: string]: unknown }; timestamp?: number; } export interface ScoringDetails { fusion_method?: 'rrf' | 'max'; keyword_rank?: number; keyword_score?: number; reranking_score?: number; vector_rank?: number; vector_score?: number; } } export interface Error { instance_id: string; message: string; } } export interface NamespaceReadResponse { created_at: string; name: string; /** * Optional description for the namespace. Max 256 characters. */ description?: string | null; public_endpoint_id?: string | null; public_endpoint_params?: NamespaceReadResponse.PublicEndpointParams | null; } export namespace NamespaceReadResponse { export interface PublicEndpointParams { authorized_hosts?: Array; chat_completions_endpoint?: PublicEndpointParams.ChatCompletionsEndpoint; /** * Custom domain hostnames that alias this public endpoint. GET and create * responses return the current set; on update (PUT) this field is only echoed back * when supplied in the request body, otherwise it is null (omit it to leave * domains unchanged). */ custom_domains?: Array | null; /** * When false, the instance is reachable only via a registered custom domain and * the default .search.ai.cloudflare.com host returns 404. * Requires at least one custom domain. Defaults to true. public_endpoint_params is * replaced wholesale on update, so resend default_domain_enabled on every update * to keep the default host off — omitting it resets to true. */ default_domain_enabled?: boolean; enabled?: boolean; /** * Instance IDs exposed through the namespace public endpoint. Empty means nothing * is searchable. Every ID must be an existing instance in this namespace, and the * list cannot exceed the account's multi-instance search limit. */ instances_allowed?: Array; mcp?: PublicEndpointParams.Mcp; rate_limit?: PublicEndpointParams.RateLimit; search_endpoint?: PublicEndpointParams.SearchEndpoint; } export namespace PublicEndpointParams { export interface ChatCompletionsEndpoint { /** * Disable chat completions endpoint for this public endpoint */ disabled?: boolean; } export interface Mcp { description?: string; /** * Disable MCP endpoint for this public endpoint */ disabled?: boolean; } export interface RateLimit { period_ms?: number; requests?: number; technique?: 'fixed' | 'sliding'; } export interface SearchEndpoint { /** * Disable search endpoint for this public endpoint */ disabled?: boolean; } } } export interface NamespaceSearchResponse { chunks: Array; query_kind: 'text' | 'image' | 'multimodal'; errors?: Array; search_query?: string; } export namespace NamespaceSearchResponse { export interface Chunk { id: string; instance_id: string; score: number; text: string; type: string; item?: Chunk.Item; scoring_details?: Chunk.ScoringDetails; } export namespace Chunk { export interface Item { key: string; metadata?: { [key: string]: unknown }; timestamp?: number; } export interface ScoringDetails { fusion_method?: 'rrf' | 'max'; keyword_rank?: number; keyword_score?: number; reranking_score?: number; vector_rank?: number; vector_score?: number; } } export interface Error { instance_id: string; message: string; } } export interface NamespaceCreateParams { /** * Path param */ account_id: string; /** * Body param */ name: string; /** * Body param: Optional description for the namespace. Max 256 characters. */ description?: string | null; /** * Body param */ public_endpoint_params?: NamespaceCreateParams.PublicEndpointParams; } export namespace NamespaceCreateParams { export interface PublicEndpointParams { authorized_hosts?: Array; chat_completions_endpoint?: PublicEndpointParams.ChatCompletionsEndpoint; /** * Custom domain hostnames that alias this public endpoint. GET and create * responses return the current set; on update (PUT) this field is only echoed back * when supplied in the request body, otherwise it is null (omit it to leave * domains unchanged). */ custom_domains?: Array | null; /** * When false, the instance is reachable only via a registered custom domain and * the default .search.ai.cloudflare.com host returns 404. * Requires at least one custom domain. Defaults to true. public_endpoint_params is * replaced wholesale on update, so resend default_domain_enabled on every update * to keep the default host off — omitting it resets to true. */ default_domain_enabled?: boolean; enabled?: boolean; /** * Instance IDs exposed through the namespace public endpoint. Empty means nothing * is searchable. Every ID must be an existing instance in this namespace, and the * list cannot exceed the account's multi-instance search limit. */ instances_allowed?: Array; mcp?: PublicEndpointParams.Mcp; rate_limit?: PublicEndpointParams.RateLimit; search_endpoint?: PublicEndpointParams.SearchEndpoint; } export namespace PublicEndpointParams { export interface ChatCompletionsEndpoint { /** * Disable chat completions endpoint for this public endpoint */ disabled?: boolean; } export interface Mcp { description?: string; /** * Disable MCP endpoint for this public endpoint */ disabled?: boolean; } export interface RateLimit { period_ms?: number; requests?: number; technique?: 'fixed' | 'sliding'; } export interface SearchEndpoint { /** * Disable search endpoint for this public endpoint */ disabled?: boolean; } } } export interface NamespaceUpdateParams { /** * Path param */ account_id: string; /** * Body param: Optional description for the namespace. Max 256 characters. */ description?: string | null; /** * Body param */ public_endpoint_params?: NamespaceUpdateParams.PublicEndpointParams | null; } export namespace NamespaceUpdateParams { export interface PublicEndpointParams { authorized_hosts?: Array; chat_completions_endpoint?: PublicEndpointParams.ChatCompletionsEndpoint; /** * Custom domain hostnames that alias this public endpoint. GET and create * responses return the current set; on update (PUT) this field is only echoed back * when supplied in the request body, otherwise it is null (omit it to leave * domains unchanged). */ custom_domains?: Array | null; /** * When false, the instance is reachable only via a registered custom domain and * the default .search.ai.cloudflare.com host returns 404. * Requires at least one custom domain. Defaults to true. public_endpoint_params is * replaced wholesale on update, so resend default_domain_enabled on every update * to keep the default host off — omitting it resets to true. */ default_domain_enabled?: boolean; enabled?: boolean; /** * Instance IDs exposed through the namespace public endpoint. Empty means nothing * is searchable. Every ID must be an existing instance in this namespace, and the * list cannot exceed the account's multi-instance search limit. */ instances_allowed?: Array; mcp?: PublicEndpointParams.Mcp; rate_limit?: PublicEndpointParams.RateLimit; search_endpoint?: PublicEndpointParams.SearchEndpoint; } export namespace PublicEndpointParams { export interface ChatCompletionsEndpoint { /** * Disable chat completions endpoint for this public endpoint */ disabled?: boolean; } export interface Mcp { description?: string; /** * Disable MCP endpoint for this public endpoint */ disabled?: boolean; } export interface RateLimit { period_ms?: number; requests?: number; technique?: 'fixed' | 'sliding'; } export interface SearchEndpoint { /** * Disable search endpoint for this public endpoint */ disabled?: boolean; } } } export interface NamespaceListParams extends V4PagePaginationArrayParams { /** * Path param */ account_id: string; /** * Query param: Filter namespaces whose name or description contains this string * (case-insensitive). */ search?: string; } export interface NamespaceDeleteParams { account_id: string; } export interface NamespaceChatCompletionsParams { /** * Path param */ account_id: string; /** * Body param */ ai_search_options: NamespaceChatCompletionsParams.AISearchOptions; /** * Body param */ messages: Array; /** * Body param */ model?: | '@cf/meta/llama-3.3-70b-instruct-fp8-fast' | '@cf/zai-org/glm-4.7-flash' | '@cf/meta/llama-3.1-8b-instruct-fast' | '@cf/meta/llama-3.1-8b-instruct-fp8' | '@cf/meta/llama-4-scout-17b-16e-instruct' | '@cf/qwen/qwen3-30b-a3b-fp8' | '@cf/deepseek-ai/deepseek-r1-distill-qwen-32b' | '@cf/moonshotai/kimi-k2-instruct' | '@cf/google/gemma-3-12b-it' | '@cf/google/gemma-4-26b-a4b-it' | '@cf/moonshotai/kimi-k2.5' | 'anthropic/claude-3-7-sonnet' | 'anthropic/claude-sonnet-4' | 'anthropic/claude-opus-4' | 'anthropic/claude-3-5-haiku' | 'cerebras/qwen-3-235b-a22b-instruct' | 'cerebras/qwen-3-235b-a22b-thinking' | 'cerebras/llama-3.3-70b' | 'cerebras/llama-4-maverick-17b-128e-instruct' | 'cerebras/llama-4-scout-17b-16e-instruct' | 'cerebras/gpt-oss-120b' | 'google-ai-studio/gemini-2.5-flash' | 'google-ai-studio/gemini-2.5-pro' | 'grok/grok-4' | 'groq/llama-3.3-70b-versatile' | 'groq/llama-3.1-8b-instant' | 'openai/gpt-5' | 'openai/gpt-5-mini' | 'openai/gpt-5-nano' | ''; /** * Body param */ stream?: boolean; [k: string]: unknown; } export namespace NamespaceChatCompletionsParams { export interface AISearchOptions { instance_ids: Array; cache?: AISearchOptions.Cache; query_rewrite?: AISearchOptions.QueryRewrite; reranking?: AISearchOptions.Reranking; retrieval?: AISearchOptions.Retrieval; } export namespace AISearchOptions { export interface Cache { cache_threshold?: 'super_strict_match' | 'close_enough' | 'flexible_friend' | 'anything_goes'; enabled?: boolean; } export interface QueryRewrite { enabled?: boolean; model?: | '@cf/meta/llama-3.3-70b-instruct-fp8-fast' | '@cf/zai-org/glm-4.7-flash' | '@cf/meta/llama-3.1-8b-instruct-fast' | '@cf/meta/llama-3.1-8b-instruct-fp8' | '@cf/meta/llama-4-scout-17b-16e-instruct' | '@cf/qwen/qwen3-30b-a3b-fp8' | '@cf/deepseek-ai/deepseek-r1-distill-qwen-32b' | '@cf/moonshotai/kimi-k2-instruct' | '@cf/google/gemma-3-12b-it' | '@cf/google/gemma-4-26b-a4b-it' | '@cf/moonshotai/kimi-k2.5' | 'anthropic/claude-3-7-sonnet' | 'anthropic/claude-sonnet-4' | 'anthropic/claude-opus-4' | 'anthropic/claude-3-5-haiku' | 'cerebras/qwen-3-235b-a22b-instruct' | 'cerebras/qwen-3-235b-a22b-thinking' | 'cerebras/llama-3.3-70b' | 'cerebras/llama-4-maverick-17b-128e-instruct' | 'cerebras/llama-4-scout-17b-16e-instruct' | 'cerebras/gpt-oss-120b' | 'google-ai-studio/gemini-2.5-flash' | 'google-ai-studio/gemini-2.5-pro' | 'grok/grok-4' | 'groq/llama-3.3-70b-versatile' | 'groq/llama-3.1-8b-instant' | 'openai/gpt-5' | 'openai/gpt-5-mini' | 'openai/gpt-5-nano' | ''; rewrite_prompt?: string; } export interface Reranking { enabled?: boolean; match_threshold?: number; model?: '@cf/baai/bge-reranker-base' | ''; } export interface Retrieval { /** * 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. */ boost_by?: Array; context_expansion?: number; filters?: { [key: string]: unknown }; fusion_method?: 'max' | 'rrf'; /** * Controls which documents are candidates for BM25 scoring. 'and' restricts * candidates to documents containing all query terms; 'or' includes any document * containing at least one term, ranked by BM25 relevance. When omitted, falls back * to the instance-level retrieval_options.keyword_match_mode, then to 'and'. */ keyword_match_mode?: 'and' | 'or'; match_threshold?: number; max_num_results?: number; retrieval_type?: 'vector' | 'keyword' | 'hybrid'; return_on_failure?: boolean; } export namespace Retrieval { export interface BoostBy { /** * 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. */ field: string; /** * 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. */ direction?: 'asc' | 'desc' | 'exists' | 'not_exists'; } } } export interface Message { content: string | Array | null; role: 'system' | 'developer' | 'user' | 'assistant' | 'tool'; [k: string]: unknown; } export namespace Message { export interface UnionMember0 { text: string; type: 'text'; } export interface UnionMember1 { image_url: UnionMember1.ImageURL; type: 'image_url'; } export namespace UnionMember1 { export interface ImageURL { url: string; } } export interface UnionMember2 { file: UnionMember2.File; type: 'file'; } export namespace UnionMember2 { export interface File { filename: string; file_data?: string; file_id?: string; } } } } export interface NamespaceReadParams { account_id: string; } export interface NamespaceSearchParams { /** * Path param */ account_id: string; /** * Body param */ ai_search_options: NamespaceSearchParams.AISearchOptions; /** * Body param: OpenAI-compatible message array. For multimodal queries, set the * last user message's `content` to an array of typed parts: * `[{type:'text', text:'…'}, {type:'image_url', image_url:{url:'…'}}]`. Image * inputs require the RAG's embedding_model to declare 'image' in * supported_modalities. */ messages?: Array; /** * Body param: A simple text query string. Alternative to 'messages' — provide * either this or 'messages', not both. */ query?: string; } export namespace NamespaceSearchParams { export interface AISearchOptions { instance_ids: Array; cache?: AISearchOptions.Cache; query_rewrite?: AISearchOptions.QueryRewrite; reranking?: AISearchOptions.Reranking; retrieval?: AISearchOptions.Retrieval; } export namespace AISearchOptions { export interface Cache { cache_threshold?: 'super_strict_match' | 'close_enough' | 'flexible_friend' | 'anything_goes'; enabled?: boolean; } export interface QueryRewrite { enabled?: boolean; model?: | '@cf/meta/llama-3.3-70b-instruct-fp8-fast' | '@cf/zai-org/glm-4.7-flash' | '@cf/meta/llama-3.1-8b-instruct-fast' | '@cf/meta/llama-3.1-8b-instruct-fp8' | '@cf/meta/llama-4-scout-17b-16e-instruct' | '@cf/qwen/qwen3-30b-a3b-fp8' | '@cf/deepseek-ai/deepseek-r1-distill-qwen-32b' | '@cf/moonshotai/kimi-k2-instruct' | '@cf/google/gemma-3-12b-it' | '@cf/google/gemma-4-26b-a4b-it' | '@cf/moonshotai/kimi-k2.5' | 'anthropic/claude-3-7-sonnet' | 'anthropic/claude-sonnet-4' | 'anthropic/claude-opus-4' | 'anthropic/claude-3-5-haiku' | 'cerebras/qwen-3-235b-a22b-instruct' | 'cerebras/qwen-3-235b-a22b-thinking' | 'cerebras/llama-3.3-70b' | 'cerebras/llama-4-maverick-17b-128e-instruct' | 'cerebras/llama-4-scout-17b-16e-instruct' | 'cerebras/gpt-oss-120b' | 'google-ai-studio/gemini-2.5-flash' | 'google-ai-studio/gemini-2.5-pro' | 'grok/grok-4' | 'groq/llama-3.3-70b-versatile' | 'groq/llama-3.1-8b-instant' | 'openai/gpt-5' | 'openai/gpt-5-mini' | 'openai/gpt-5-nano' | ''; rewrite_prompt?: string; } export interface Reranking { enabled?: boolean; match_threshold?: number; model?: '@cf/baai/bge-reranker-base' | ''; } export interface Retrieval { /** * 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. */ boost_by?: Array; context_expansion?: number; filters?: { [key: string]: unknown }; fusion_method?: 'max' | 'rrf'; /** * Controls which documents are candidates for BM25 scoring. 'and' restricts * candidates to documents containing all query terms; 'or' includes any document * containing at least one term, ranked by BM25 relevance. When omitted, falls back * to the instance-level retrieval_options.keyword_match_mode, then to 'and'. */ keyword_match_mode?: 'and' | 'or'; match_threshold?: number; max_num_results?: number; retrieval_type?: 'vector' | 'keyword' | 'hybrid'; return_on_failure?: boolean; } export namespace Retrieval { export interface BoostBy { /** * 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. */ field: string; /** * 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. */ direction?: 'asc' | 'desc' | 'exists' | 'not_exists'; } } } export interface Message { content: string | Array | null; role: 'system' | 'developer' | 'user' | 'assistant' | 'tool'; [k: string]: unknown; } export namespace Message { export interface UnionMember0 { text: string; type: 'text'; } export interface UnionMember1 { image_url: UnionMember1.ImageURL; type: 'image_url'; } export namespace UnionMember1 { export interface ImageURL { url: string; } } export interface UnionMember2 { file: UnionMember2.File; type: 'file'; } export namespace UnionMember2 { export interface File { filename: string; file_data?: string; file_id?: string; } } } } Namespaces.Instances = Instances; Namespaces.BaseInstances = BaseInstances; export declare namespace Namespaces { export { type NamespaceCreateResponse as NamespaceCreateResponse, type NamespaceUpdateResponse as NamespaceUpdateResponse, type NamespaceListResponse as NamespaceListResponse, type NamespaceDeleteResponse as NamespaceDeleteResponse, type NamespaceChatCompletionsResponse as NamespaceChatCompletionsResponse, type NamespaceReadResponse as NamespaceReadResponse, type NamespaceSearchResponse as NamespaceSearchResponse, type NamespaceListResponsesV4PagePaginationArray as NamespaceListResponsesV4PagePaginationArray, type NamespaceCreateParams as NamespaceCreateParams, type NamespaceUpdateParams as NamespaceUpdateParams, type NamespaceListParams as NamespaceListParams, type NamespaceDeleteParams as NamespaceDeleteParams, type NamespaceChatCompletionsParams as NamespaceChatCompletionsParams, type NamespaceReadParams as NamespaceReadParams, type NamespaceSearchParams as NamespaceSearchParams, }; export { Instances as Instances, BaseInstances as BaseInstances, type InstanceCreateResponse as InstanceCreateResponse, type InstanceUpdateResponse as InstanceUpdateResponse, type InstanceListResponse as InstanceListResponse, type InstanceDeleteResponse as InstanceDeleteResponse, type InstanceChatCompletionsResponse as InstanceChatCompletionsResponse, type InstanceReadResponse as InstanceReadResponse, type InstanceSearchResponse as InstanceSearchResponse, type InstanceStatsResponse as InstanceStatsResponse, type InstanceListResponsesV4PagePaginationArray as InstanceListResponsesV4PagePaginationArray, type InstanceCreateParams as InstanceCreateParams, type InstanceUpdateParams as InstanceUpdateParams, type InstanceListParams as InstanceListParams, type InstanceDeleteParams as InstanceDeleteParams, type InstanceChatCompletionsParams as InstanceChatCompletionsParams, type InstanceReadParams as InstanceReadParams, type InstanceSearchParams as InstanceSearchParams, type InstanceStatsParams as InstanceStatsParams, }; }