Portkey Docs
HomeAPIIntegrationsChangelog
  • Introduction
    • What is Portkey?
    • Make Your First Request
    • Feature Overview
  • Integrations
    • LLMs
      • OpenAI
        • Structured Outputs
        • Prompt Caching
      • Anthropic
        • Prompt Caching
      • Google Gemini
      • Groq
      • Azure OpenAI
      • AWS Bedrock
      • Google Vertex AI
      • Bring Your Own LLM
      • AI21
      • Anyscale
      • Cerebras
      • Cohere
      • Fireworks
      • Deepbricks
      • Deepgram
      • Deepinfra
      • Deepseek
      • Google Palm
      • Huggingface
      • Inference.net
      • Jina AI
      • Lingyi (01.ai)
      • LocalAI
      • Mistral AI
      • Monster API
      • Moonshot
      • Nomic
      • Novita AI
      • Ollama
      • OpenRouter
      • Perplexity AI
      • Predibase
      • Reka AI
      • SambaNova
      • Segmind
      • SiliconFlow
      • Stability AI
      • Together AI
      • Voyage AI
      • Workers AI
      • ZhipuAI / ChatGLM / BigModel
      • Suggest a new integration!
    • Agents
      • Autogen
      • Control Flow
      • CrewAI
      • Langchain Agents
      • LlamaIndex
      • Phidata
      • Bring Your own Agents
    • Libraries
      • Autogen
      • DSPy
      • Instructor
      • Langchain (Python)
      • Langchain (JS/TS)
      • LlamaIndex (Python)
      • LibreChat
      • Promptfoo
      • Vercel
        • Vercel [Depricated]
  • Product
    • Observability (OpenTelemetry)
      • Logs
      • Tracing
      • Analytics
      • Feedback
      • Metadata
      • Filters
      • Logs Export
      • Budget Limits
    • AI Gateway
      • Universal API
      • Configs
      • Multimodal Capabilities
        • Image Generation
        • Function Calling
        • Vision
        • Speech-to-Text
        • Text-to-Speech
      • Cache (Simple & Semantic)
      • Fallbacks
      • Automatic Retries
      • Load Balancing
      • Conditional Routing
      • Request Timeouts
      • Canary Testing
      • Virtual Keys
        • Budget Limits
    • Prompt Library
      • Prompt Templates
      • Prompt Partials
      • Retrieve Prompts
      • Advanced Prompting with JSON Mode
    • Guardrails
      • List of Guardrail Checks
        • Patronus AI
        • Aporia
        • Pillar
        • Bring Your Own Guardrails
      • Creating Raw Guardrails (in JSON)
    • Autonomous Fine-tuning
    • Enterprise Offering
      • Org Management
        • Organizations
        • Workspaces
        • User Roles & Permissions
        • API Keys (AuthN and AuthZ)
      • Access Control Management
      • Budget Limits
      • Security @ Portkey
      • Logs Export
      • Private Cloud Deployments
        • Architecture
        • AWS
        • GCP
        • Azure
        • Cloudflare Workers
        • F5 App Stack
      • Components
        • Log Store
          • MongoDB
    • Open Source
    • Portkey Pro & Enterprise Plans
  • API Reference
    • Introduction
    • Authentication
    • OpenAPI Specification
    • Headers
    • Response Schema
    • Gateway Config Object
    • SDK
  • Provider Endpoints
    • Supported Providers
    • Chat
    • Embeddings
    • Images
      • Create Image
      • Create Image Edit
      • Create Image Variation
    • Audio
      • Create Speech
      • Create Transcription
      • Create Translation
    • Fine-tuning
      • Create Fine-tuning Job
      • List Fine-tuning Jobs
      • Retrieve Fine-tuning Job
      • List Fine-tuning Events
      • List Fine-tuning Checkpoints
      • Cancel Fine-tuning
    • Batch
      • Create Batch
      • List Batch
      • Retrieve Batch
      • Cancel Batch
    • Files
      • Upload File
      • List Files
      • Retrieve File
      • Retrieve File Content
      • Delete File
    • Moderations
    • Assistants API
      • Assistants
        • Create Assistant
        • List Assistants
        • Retrieve Assistant
        • Modify Assistant
        • Delete Assistant
      • Threads
        • Create Thread
        • Retrieve Thread
        • Modify Thread
        • Delete Thread
      • Messages
        • Create Message
        • List Messages
        • Retrieve Message
        • Modify Message
        • Delete Message
      • Runs
        • Create Run
        • Create Thread and Run
        • List Runs
        • Retrieve Run
        • Modify Run
        • Submit Tool Outputs to Run
        • Cancel Run
      • Run Steps
        • List Run Steps
        • Retrieve Run Steps
    • Completions
    • Gateway for Other API Endpoints
  • Portkey Endpoints
    • Configs
      • Create Config
      • List Configs
      • Retrieve Config
      • Update Config
    • Feedback
      • Create Feedback
      • Update Feedback
    • Guardrails
    • Logs
      • Insert a Log
      • Log Exports [BETA]
        • Retrieve a Log Export
        • Update a Log Export
        • List Log Exports
        • Create a Log Export
        • Start a Log Export
        • Cancel a Log Export
        • Download a Log Export
    • Prompts
      • Prompt Completion
      • Render
    • Virtual Keys
      • Create Virtual Key
      • List Virtual Keys
      • Retrieve Virtual Key
      • Update Virtual Key
      • Delete Virtual Key
    • Analytics
      • Graphs - Time Series Data
        • Get Requests Data
        • Get Cost Data
        • Get Latency Data
        • Get Tokens Data
        • Get Users Data
        • Get Requests per User
        • Get Errors Data
        • Get Error Rate Data
        • Get Status Code Data
        • Get Unique Status Code Data
        • Get Rescued Requests Data
        • Get Cache Hit Rate Data
        • Get Cache Hit Latency Data
        • Get Feedback Data
        • Get Feedback Score Distribution Data
        • Get Weighted Feeback Data
        • Get Feedback Per AI Models
      • Summary
        • Get All Cache Data
      • Groups - Paginated Data
        • Get User Grouped Data
        • Get Model Grouped Data
        • Get Metadata Grouped Data
    • API Keys [BETA]
      • Update API Key
      • Create API Key
      • Delete an API Key
      • Retrieve an API Key
      • List API Keys
    • Admin
      • Users
        • Retrieve a User
        • Retrieve All Users
        • Update a User
        • Remove a User
      • User Invites
        • Invite a User
        • Retrieve an Invite
        • Retrieve All User Invites
        • Delete a User Invite
      • Workspaces
        • Create Workspace
        • Retrieve All Workspaces
        • Retrieve a Workspace
        • Update Workspace
        • Delete a Workspace
      • Workspace Members
        • Add a Workspace Member
        • Retrieve All Workspace Members
        • Retrieve a Workspace Member
        • Update Workspace Member
        • Remove Workspace Member
  • Guides
    • Getting Started
      • A/B Test Prompts and Models
      • Tackling Rate Limiting
      • Function Calling
      • Image Generation
      • Getting started with AI Gateway
      • Llama 3 on Groq
      • Return Repeat Requests from Cache
      • Trigger Automatic Retries on LLM Failures
      • 101 on Portkey's Gateway Configs
    • Integrations
      • Llama 3 on Portkey + Together AI
      • Introduction to GPT-4o
      • Anyscale
      • Mistral
      • Vercel AI
      • Deepinfra
      • Groq
      • Langchain
      • Mixtral 8x22b
      • Segmind
    • Use Cases
      • Few-Shot Prompting
      • Enforcing JSON Schema with Anyscale & Together
      • Detecting Emotions with GPT-4o
      • Build an article suggestion app with Supabase pgvector, and Portkey
      • Setting up resilient Load balancers with failure-mitigating Fallbacks
      • Run Portkey on Prompts from Langchain Hub
      • Smart Fallback with Model-Optimized Prompts
      • How to use OpenAI SDK with Portkey Prompt Templates
      • Setup OpenAI -> Azure OpenAI Fallback
      • Fallback from SDXL to Dall-e-3
      • Comparing Top10 LMSYS Models with Portkey
      • Build a chatbot using Portkey's Prompt Templates
  • Support
    • Contact Us
    • Developer Forum
    • Common Errors & Resolutions
    • December '23 Migration
    • Changelog
Powered by GitBook
On this page
  • Compatibility & Deprecation List
  • Major Version Release of the SDK
  • Here's What's New:
  • Here's What's Changed:
  • All-New APIs
  • Here's What's New:
  • Here's What's Changed
  • Simlarly, for Prompts
  • Configs 2.0
  • Here's What's New
  • Here's What's Changed
  • Support

Was this helpful?

Edit on GitHub
  1. Support

December '23 Migration

PreviousCommon Errors & Resolutions

Last updated 1 year ago

Was this helpful?

Date: 8th Dec, 2023

This December, we're pushing out some exciting new updates to Portkey's SDKs, APIs, and Configs.

are upped to major version 1.0 bringing parity with the new OpenAI SDK structure and adding Portkey production features to it. We are also bringing native Langchain & Llamaindex integrations inside the SDK. This is a Breaking Change that Requires Migration.

are upgraded with new endpoints, making it simpler to do /chat/completions and /completions calls and adding Portkey's production functionalities to them.

This is a Breaking Change that Requires Migration.

are upgraded to version 2.0, bringing nested gateway strategies with granular handling. For Configs saved in the Portkey dashboard, this is NOT a Breaking Change and we will Auto Migrate your old Configs. For Configs directly defined at the time of making a call, through the old SDKs or old APIS, they will fail on the new APIs & SDKs and require migration.

Compatibility & Deprecation List

List
Compatibility
Deprecation Date

API (Old) /v1/proxy /v1/complete /v1/chatComplete /v1/embed /v1/prompts/ID/generate

✅ SDK (Old) ❌ SDK (New) ✅ Configs (Old) ✅ Configs (New)

Q2 '24

API (New) /v1 /v1/completions /v1/chat/completions /v1/embeddings /v1/prompts/ID/completions

❌ SDK (Old) ✅ SDK (New) ❌ Configs (Old) ✅ Configs (New)

-

SDK Version < 1 (Old)

✅ API (Old) ❌ API (New) ✅ Configs (Old) ✅ Configs (new)

Q2 '24

SDK Version = 1 (New)

❌ API (Old) ✅ API (New) ✅ Configs (Old) ✅ Configs (new)

-

Configs 1.0 (Old)

✅ API (Old)

❌ API (New) ✅ SDK (Old) ❌ SDK (new) === Configs saved through the Portkey UI will be auto migrated.

Q2 '24

Configs 2.0 (New)

✅ API (Old)

✅ API (New) ✅ SDK (Old) ✅ SDK (new)

-

We recommend upgrading to these new versions promptly to take full advantage of their capabilities. While your existing code will continue to work until the deprecation date around Q2 '24, transitioning now ensures you stay ahead of the curve and avoid any future service interruptions. Follow along with this guide!


Major Version Release of the SDK

Here's What's New:

  1. More extensible SDK that can be used with many more LLM providers

  2. Out-of-the-box support for streaming

  3. Completely follows OpenAI's SDK signature reducing your technical debt

  4. Native support for Langchain & Llamaindex within the SDK (Python)

  5. Support for the Portkey Feedback endpoint

  6. Support for Portkey Prompt Templates

  7. Older SDK versions to be deprecated soon

Here's What's Changed:

FROM ➡

import portkey
from portkey import Config, LLMOptions

portkey.config = Config(
    mode="single",
    llms=LLMOptions(provider="openai", api_key="OPENAI_API_KEY")
)

response = portkey.ChatCompletions.create(
    model="gpt-4", 
    messages=[
        {"role": "user","content": "Hello World!"}
    ]
)

TO ⬇

from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    Authorization="OPENAI_KEY"
)

response = portkey.chat.completions.create(
    messages=[{'role': 'user', 'content': 'Say this is a test'}],
    model='gpt-3.5-turbo'
)

print(response)

Installing the New SDK,

pip install -U portkey-ai

FROM ➡

import { Portkey } from "portkey-ai";

const portkey = new Portkey({
    mode: "single",
    llms: [{ provider: "openai", virtual_key: "open-ai-xxx" }]
});

async function main() {
    const chatCompletion = await portkey.chat.completions.create({
        messages: [{ role: 'user', content: 'Say this is a test' }],
        model: 'gpt-4'
    });

    console.log(chatCompletion.choices);
};

main();

TO ⬇

import Portkey from 'portkey-ai';

// Initialize the Portkey client
const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY",  // Replace with your Portkey API key
    Authorization: "OPENAI_KEY" 
});

// Generate a chat completion
async function getChatCompletion() {
    const chatCompletion = await portkey.chat.completions.create({
        messages: [{ role: 'user', content: 'Say this is a test' }],
        model: 'gpt-3.5-turbo',
    });

    console.log(chatCompletion);
}
getChatCompletion();

Installing the New SDK:

npm i -U portkey-ai

All-New APIs

Here's What's New:

  1. Introduced 3 new routes /chat/completions, /completions, and /embeddings

  2. Simplified the headers:

    1. x-portkey-mode header is deprecated and replaced with x-portkey-provider

      1. Which takes values: openai, anyscale, cohere, palm, azure-openai, and more.

    2. New header x-portkey-virtual-key is introduced.

  3. /complete and /chatComplete endpoints to be deprecated soon

  4. Prompts endpoint /prompts/$PROMPT_ID/generate is upgraded to /prompts/$PROMPT_ID/completions and the old route will be deprecated soon

    1. We now support updating the model params on-the-fly (i.e. changing temperature etc at the time of making a call)

    2. Prompt response object on the /completions route is now fully OpenAI compliant

  5. New /gateway endpoint that lets you make calls to third-party LLM providers easily

Here's What's Changed

FROM ➡

from openai import OpenAI

client = OpenAI(
    api_key="OPENAI_API_KEY", # defaults to os.environ.get("OPENAI_API_KEY")
    base_url="https://api.portkey.ai/v1/proxy",
    default_headers= {
        "x-portkey-api-key": "PORTKEY_API_KEY",
        "x-portkey-mode": "proxy openai",
        "Content-Type": "application/json"
    }
)

chat_complete = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Say this is a test"}],
)

print(chat_complete.choices[0].message.content)

TO ⬇

# pip install -U portkey-ai 

from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders

client = OpenAI(
    api_key="OPENAI_API_KEY", # defaults to os.environ.get("OPENAI_API_KEY")
    base_url=PORTKEY_GATEWAY_URL,
    default_headers=createHeaders(
        provider="openai",
        api_key="PORTKEY_API_KEY" # defaults to os.environ.get("PORTKEY_API_KEY")
    )
)

chat_complete = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Say this is a test"}],
)

print(chat_complete.choices[0].message.content)

FROM ➡

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: 'OPENAI_API_KEY', // defaults to process.env["OPENAI_API_KEY"],
  baseURL: "https://api.portkey.ai/v1/proxy",
  defaultHeaders:{
    "x-portkey-api-key": "PORTKEY_API_KEY",
    "x-portkey-mode": "proxy openai",
    "Content-Type": "application/json"
  }
});

async function main() {
  const chatCompletion = await openai.chat.completions.create({
    messages: [{ role: 'user', content: 'Say this is a test' }],
    model: 'gpt-3.5-turbo',
  });

  console.log(chatCompletion.choices);
}

main();

TO ⬇

// npm i portkey-ai

import OpenAI from 'openai'; // We're using the v4 SDK
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'

const openai = new OpenAI({
  apiKey: 'OPENAI_API_KEY', // defaults to process.env["OPENAI_API_KEY"],
  baseURL: PORTKEY_GATEWAY_URL,
  defaultHeaders: createHeaders({
    provider: "openai",
    apiKey: "PORTKEY_API_KEY" // defaults to process.env["PORTKEY_API_KEY"]
  })
});

async function main() {
  const chatCompletion = await openai.chat.completions.create({
    messages: [{ role: 'user', content: 'Say this is a test' }],
    model: 'gpt-3.5-turbo',
  });

  console.log(chatCompletion.choices);
}

main();

FROM ➡

curl http://api.portkey.ai/v1/proxy/completions \
  -H 'x-portkey-api-key: $PORTKEY_API_KEY' \
  -H 'x-portkey-mode: proxy openai' \
  -H 'Authorization: Bearer <OPENAI_API_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Top 20 tallest buildings in the world"
  }'

TO ⬇

curl https://api.portkey.ai/v1/completions \
  -H "x-portkey-api-key: $PORTKEY_API_KEY" \
  -H "x-portkey-provider: openai" \ 
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Top 20 tallest buildings in the world"
  }'

Simlarly, for Prompts

FROM ➡

curl https://api.portkey.ai/v1/prompts/$PROMPT_ID/generate \
  -H 'x-portkey-api-key: $PORTKEY_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"variables": {"variable_a": "", "variable_b": ""}}'

TO ⬇

curl https://api.portkey.ai/v1/prompts/$PROMPT_ID/completions \
  -H 'x-portkey-api-key: $PORTKEY_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"variables": {"variable_a": "", "variable_b": ""}}'
# pip install portkey-ai

from portkey-ai import Portkey

client = Portkey(api_key="PORTKEY_API_KEY")

response = client.prompts.completions.create(
    prompt_id="Prompt_ID",
    variables={
       # The variables specified in the prompt
    },
    max_tokens=250,
    presence_penalty=0.2,
    temperature=0.1
)
print(prompt_completion)

Configs 2.0

Here's What's New

  1. New concept of strategy instead of standalone mode. You can now build bespoke gateway strategies and nest them in a single config.

  2. You can also trigger a specific strategy on specific error codes.

  3. New concept of targets that replace options in the previous Config

  4. If you are adding virtual_key to the target array, you no longer need to add provider,Portkey will pick up the Provider directly from the Virtual Key!

  5. For Azure, only now pass the virtual_key - it takes care of all other Azure params like Deployment name, API version etc.

The Configs UI on Portkey app will autocomplete Configs ONLY in the new format now. All your existing Configs are auto migrated.

Here's What's Changed

FROM ➡

{
	"mode": "single",
	"options": [
		{
			"provider": "openai",
			"virtual_key": "open-4110dd",
		}
	]
}

TO ⬇

{
	"strategy": {
		"mode":"single"
	},
	"targets": [
		{
			"virtual_key": "open-4110dd"
		}
	]
}

Support

Shoot ANY questions or queries you have on the migration to the Portkey team and we will try to get back to you ASAP.

SDK
Chat
Completions
Gateway for Other API Endpoints
Prompts
Gateway Config Object
on our Discord
Portkey's SDKs
Portkey's APIs
Configs