> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orq.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Router.Completions SDK Reference

> SDK reference for the Router.Completions API, available in Node.js and Python.

## Router.Completions

### Create a Completion

For sending requests to legacy completion models

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.router.completions.create(model="XC90", prompt="<value>", echo=False, frequency_penalty=0, max_tokens=16, presence_penalty=0, temperature=1, top_p=1, n=1, retry={
          "on_codes": [
              429,
              500,
              502,
              503,
              504,
          ],
      }, cache={
          "ttl": 3600,
          "type": "exact_match",
      }, load_balancer={
          "type": "weight_based",
          "models": [
              {
                  "model": "openai/gpt-4o",
                  "weight": 0.7,
              },
          ],
      }, timeout={
          "call_timeout": 30000,
      }, stream=False)

      with res as event_stream:
          for event in event_stream:
              # handle event
              print(event, flush=True)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.router.completions.create({
      model: "XC90",
      prompt: "<value>",
      retry: {
        onCodes: [
          429,
          500,
          502,
          503,
          504,
        ],
      },
      cache: {
        ttl: 3600,
        type: "exact_match",
      },
      loadBalancer: {
        type: "weight_based",
        models: [
          {
            model: "openai/gpt-4o",
            weight: 0.7,
          },
        ],
      },
      timeout: {
        callTimeout: 30000,
      },
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "model": str,  # required
        "prompt": str,  # required
        "echo": OptionalNullable[bool],
        "frequency_penalty": OptionalNullable[float],
        "max_tokens": OptionalNullable[float],
        "presence_penalty": OptionalNullable[float],
        "seed": OptionalNullable[float],
        "stop": Union[str, List[str]],
        "temperature": OptionalNullable[float],
        "top_p": OptionalNullable[float],
        "n": OptionalNullable[float],
        "user": Optional[str],
        "name": Optional[str],
        "fallbacks": {  # optional
            "model": str,  # required
        },
        "retry": {  # optional
            "count": Optional[float],
            "on_codes": List[float],
        },
        "cache": {  # optional
            "ttl": Optional[float],
            "type": Literal["exact_match"],  # required
        },
        "load_balancer": Union[CreateCompletionLoadBalancer1],
        "timeout": {  # optional
            "call_timeout": float,  # required
        },
        "thinking": Union[ThinkingConfigDisabledSchema, ThinkingConfigEnabledSchema, ThinkingConfigAdaptiveSchema],
        "plugins": Union[PIIRedactionPluginAuto, PIIRedactionPluginEn, PIIRedactionPluginNl],
        "orq": {  # optional
            "name": Optional[str],
            "retry": {  # optional
                "count": Optional[float],
                "on_codes": List[float],
            },
            "fallbacks": {  # optional
                "model": str,  # required
            },
            "prompt": {  # optional
                "id": str,  # required
                "version": Literal["latest"],  # required
            },
            "identity": {  # optional
                "id": str,  # required
                "display_name": Optional[str],
                "email": Optional[str],
                "metadata": List[Dict[str, Any]],
                "logo_url": Optional[str],
                "tags": List[str],
            },
            "~~`contact`~~": {  # optional
                "id": str,  # required
                "display_name": Optional[str],
                "email": Optional[str],
                "metadata": List[Dict[str, Any]],
                "logo_url": Optional[str],
                "tags": List[str],
            },
            "thread": {  # optional
                "id": str,  # required
                "tags": List[str],
            },
            "~~`inputs`~~": Union[Dict[str, Any], List[CreateCompletionInputs2]],
            "cache": {  # optional
                "ttl": Optional[float],
                "type": Literal["exact_match"],  # required
            },
            "knowledge_bases": {  # optional
                "top_k": Optional[int],
                "threshold": Optional[float],
                "search_type": Optional[Literal["vector_search", "keyword_search", "hybrid_search"]],
                "filter_by": Union[Dict[str, CreateCompletionFilterBy1], CreateCompletionFilterByAnd, CreateCompletionFilterByOr],
                "search_options": {  # optional
                    "include_vectors": Optional[bool],
                    "include_metadata": Optional[bool],
                    "include_scores": Optional[bool],
                },
                "rerank_config": {  # optional
                    "model": str,  # required
                    "threshold": Optional[float],
                    "top_k": Optional[int],
                },
                "agentic_rag_config": {  # optional
                    "model": str,  # required
                },
                "knowledge_id": str,  # required
                "query": Optional[str],
            },
            "load_balancer": Union[CreateCompletionLoadBalancerRouterCompletions1],
            "timeout": {  # optional
                "call_timeout": float,  # required
            },
        },
        "stream": Optional[bool],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      model: string;  // required
      prompt: string;  // required
      echo?: boolean;
      frequencyPenalty?: number;
      maxTokens?: number;
      presencePenalty?: number;
      seed?: number;
      stop?: string | string[];
      temperature?: number;
      topP?: number;
      n?: number;
      user?: string;
      name?: string;
      fallbacks?: {
        model: string;  // required
      };
      retry?: {
        count?: number;
        onCodes?: number[];
      };
      cache?: {
        ttl?: number;
        type: string;  // required
      };
      loadBalancer?: string;
      timeout?: {
        callTimeout: number;  // required
      };
      thinking?: string;
      plugins?: string;
      ~~`orq`~~?: {
        name?: string;
        retry?: {
          count?: number;
          onCodes?: number[];
        };
        fallbacks?: {
          model: string;  // required
        };
        prompt?: {
          id: string;  // required
          version: string;  // required
        };
        identity?: {
          id: string;  // required
          displayName?: string;
          email?: string;
          metadata?: Record<string, any>[];
          logoUrl?: string;
          tags?: string[];
        };
        ~~`contact`~~?: {
          id: string;  // required
          displayName?: string;
          email?: string;
          metadata?: Record<string, any>[];
          logoUrl?: string;
          tags?: string[];
        };
        thread?: {
          id: string;  // required
          tags?: string[];
        };
        ~~`inputs`~~?: string;
        cache?: {
          ttl?: number;
          type: string;  // required
        };
        knowledgeBases?: {
          topK?: number;
          threshold?: number;
          searchType?: string;
          filterBy?: string;
          searchOptions?: {
            includeVectors?: boolean;
            includeMetadata?: boolean;
            includeScores?: boolean;
          };
          rerankConfig?: {
            model: string;  // required
            threshold?: number;
            topK?: number;
          };
          agenticRagConfig?: {
            model: string;  // required
          };
          knowledgeId: string;  // required
          query?: string;
        };
        loadBalancer?: string;
        timeout?: {
          callTimeout: number;  // required
        };
      };
      stream?: boolean;
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": str,
        "choices": {
            "finish_reason": Literal["stop", "length", "content_filter", "tool_calls"],
            "index": float,
            "text": str,
        },
        "created": Union[str, float],
        "model": str,
        "system_fingerprint": Optional[str],
        "object": str,
        "usage": {  # optional
            "completion_tokens": Optional[float],
            "prompt_tokens": Optional[float],
            "total_tokens": Optional[float],
            "prompt_tokens_details": {  # optional
                "cached_tokens": OptionalNullable[int],
                "cache_creation_tokens": OptionalNullable[int],
                "audio_tokens": OptionalNullable[int],
            },
            "completion_tokens_details": {  # optional
                "reasoning_tokens": OptionalNullable[float],
                "accepted_prediction_tokens": OptionalNullable[float],
                "rejected_prediction_tokens": OptionalNullable[float],
                "audio_tokens": OptionalNullable[int],
            },
        },
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id: string;
      choices: {
        finish_reason: "stop" | "length" | "content_filter" | "tool_calls";
        index: number;
        text: string;
      };
      created?: string | number;
      model: string;
      system_fingerprint?: string | undefined;
      object: string;
      usage?: {
        completion_tokens?: number | undefined;
        prompt_tokens?: number | undefined;
        total_tokens?: number | undefined;
        prompt_tokens_details?: {
          cached_tokens?: number | null | undefined;
          cache_creation_tokens?: number | null | undefined;
          audio_tokens?: number | null | undefined;
        };
        completion_tokens_details?: {
          reasoning_tokens?: number | null | undefined;
          accepted_prediction_tokens?: number | null | undefined;
          rejected_prediction_tokens?: number | null | undefined;
          audio_tokens?: number | null | undefined;
        };
      };
    }
    ```
  </CodeGroup>
</Expandable>
