Skip to main content

Router.Completions

Create a Completion

For sending requests to legacy completion models
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)

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();