OpenAI - Prompt Management

This article guides you through integrating your SaaS with and OpenAI using our Python SDK. By the end of the article, you'll know how to set up a prompt in, perform prompt engineering, request a prompt variant using the SDK code generator, map the response with OpenAI, send a payload to OpenAI, and report the response back to for observability and monitoring.

This guide shows you how to integrate your products with OpenAI using the Python SDK.

Step 1: Install the SDK

# orquesta sdk
pip install orquesta-sdk

# OpenAI
pip install openai
// orquesta sdk
npm install @orquesta/node --save
yarn add @orquesta/node

// OpenAI
npm install --save openai
yarn add openai

Step 2: Enable models in the Model Garden allows you to pick and enable the models of your choice and work with them. Enabling a model(s) is very easy; all you have to do is navigate to the Model Garden and toggle on the model of your choice.

Step 3: Execute prompt

You can find your API key in your workspace<workspace-name>/settings/developers

from orquesta_sdk import OrquestaClientOptions, Orquesta
from openai import OpenAI

api_key = "ORQUESTA_API_KEY"

# Initialize Orquesta client
options = OrquestaClientOptions(

client = Orquesta(options)

# Getting the deployment config

config = client.deployments.get_config(
  context={ "environments": [ "production" ], "country": [ "NLD", "BEL" ], "locale": [ "en" ], "user-segment": [ "b2c" ] },
  inputs={ "customer_name": "John" },

deployment_config = config.to_dict()

# Send the payload to OpenAI 
client = OpenAI(
    api_key = "OPENAI_API_KEY",
chat_completion =
    messages= deployment_config['messages'],

# Print the response
import OpenAI from 'openai';

const start = async () => {
  const { createClient } = await import('@orquesta/node');

  // Initialize Orquesta client
  const client = createClient({
    apiKey: 'ORQUESTA_API_KEY',
    environment: 'production',

  // Getting the deployment config
  const deploymentConfig = await client.deployments.getConfig({
    key: 'Deployment-with-OpenAI',
    context: {
      environments: ['production'],
      country: ['NLD', 'BEL'],
      locale: ['en'],
      'user-segment': ['b2c'],
    inputs: {
      customer_name: 'John',
    metadata: {
      'custom-field-name': 'custom-metadata-value',


  const deploymentConfigObj: any = deploymentConfig;
  // Send the payload to OpenAI
  const openaiApiKey: string = 'OPENAI_API_KEY';

  const openai = new OpenAI({
    apiKey: openaiApiKey, // This is your openai api key

  const chatCompletion = await{
    messages: deploymentConfigObj.messages,
    model: deploymentConfigObj.model,

  // Print the response

// Call the async function

Step 4: Additional metrics to the request

After receiving your results from OpenAI, add metrics to the transaction using the add_metrics method to complete the missing data for your Logging and Monitoring

# Additional informatiom
  feedback={"score": 90},
      "custom": "custom_metadata",
      "chain_id": "ad1231xsdaABw",
      "prompt_tokens": 100,
      "completion_tokens": 900,
      "total_tokens": 1000,
      "latency": 9000,
      "time_to_first_token": 250,
  chain_id: "c4a75b53-62fa-401b-8e97-493f3d299316",
  conversation_id: "ee7b0c8c-eeb2-43cf-83e9-a4a49f8f13ea",
  user_id: "e3a202a6-461b-447c-abe2-018ba4d04cd0",
  feedback: {
    score: 100
  metadata: {
    custom: "custom_metadata",
    chain_id: "ad1231xsdaABw"
  usage: {
    prompt_tokens: 100,
    completion_tokens: 900,
    total_tokens: 1000
  performance: {
    latency: 9000,
    time_to_first_token: 250