We recommend to use our official client libraries to interact with the orq.ai API

Github

Our SDKs are available on Github:



Installation

# The SDK can be installed with either pip or poetry package managers.
# PIP

pip install orq-ai-sdk

# Poetry

poetry add orq-ai-sdk
# The SDK can be installed with either npm, pnpm, bun or yarn package managers.
# NPM

npm add @orq-ai/node

# PNPM

pnpm add @orq-ai/node

# Bun

bun add @orq-ai/node

# Yarn

yarn add @orq-ai/node zod

# Note that Yarn does not install peer dependencies automatically. You will need
# to install zod as shown above.

Usage

You can get your workspace API keys from the settings section in your orq.ai workspace. https://my.orq.ai/<workspace>/settings/developers

Initialize the orq.ai client with your API key:

import os

from orq_ai_sdk import OrqAI

client = OrqAI(
	 api_key=os.environ.get("ORQ_API_KEY", "__API_KEY__"),
 	 environment="production"
)
import os

from orq_ai_sdk import AsyncOrqAI

client = AsyncOrqAI(
	api_key=os.environ.get("ORQUESTA_API_KEY", "__API_KEY__"),
  environment="production"
)
import { createClient } from '@orq-ai/node';

const client = createClient({
  apiKey: 'orq-api-key',
  environment: 'production',
});

Set the contact after the client has been initialized.

Setting a contact identifier in the client is crucial for precisely tracking individual user requests. This enhances personalized user experiences and improves security by ensuring accurate user activity monitoring and efficient management.

client.set_contact(id=2024)
client.setContact({id: 2024})

Deployments

The Deployments API delivers text outputs, images, or tool calls based on the configuration established within orq.ai for your deployments. Additionally, this API supports streaming. It is highly recommended that you use the code snippets from the orq.ai Admin panel to ensure ease of use and minimize errors.


Invoke a deployment

invoke()

generation = client.deployments.invoke(
    key="customer_service",
    context={"environments": "production", "country": "NLD"},
    inputs={"firstname": "John", "city": "New York"},
    metadata={"customer_id": "Qwtqwty90281"},
)

print(generation.choices[0].message.content)
generation = await client.deployments.invoke(
    key="customer_service",
    context={"environments": "production", "country": "NLD"},
    inputs={"firstname": "John", "city": "New York"},
    metadata={"customer_id": "Qwtqwty90281"},
)

print(generation.choices[0].message.content)
const deployment = await client.deployments.invoke({
  key: 'customer_service',
  context: { environments: 'production', country: 'NLD' },
  inputs: { firstname: 'John', city: 'New York' },
  metadata: { customer_id: 'Qwtqwty90281' },
});

console.log(deployment?.choices[0].message.content);

📘

Learn more about Invoke() reading the Python and Node.js docs.

Deployments can also be streamed:

Read more about using the SDK to interact with the Deployments API with Python and Node.js.


Other Resources and Operations

Read more on the Github SDK Documentation for all Resources and Operations: