Integrate Databricks Model Serving with Portkeyโs AI Gateway
Portkey provides a robust and secure gateway to integrate various Large Language Models (LLMs) into applications, including Databricks Model Serving endpoints.With Portkey, take advantage of features like fast AI gateway access, observability, prompt management, and more, while securely managing API keys through Model Catalog.
from portkey_ai import Portkey# 1. Install: pip install portkey-ai# 2. Add @databricks provider in model catalog# 3. Use it:portkey = Portkey(api_key="PORTKEY_API_KEY")response = portkey.chat.completions.create( model="@databricks/databricks-meta-llama-3-1-70b-instruct", messages=[{"role": "user", "content": "Say this is a test"}])print(response.choices[0].message.content)
import Portkey from 'portkey-ai'// 1. Install: npm install portkey-ai// 2. Add @databricks provider in model catalog// 3. Use it:const portkey = new Portkey({ apiKey: "PORTKEY_API_KEY"})const response = await portkey.chat.completions.create({ model: "@databricks/databricks-meta-llama-3-1-70b-instruct", messages: [{ role: "user", content: "Say this is a test" }]})console.log(response.choices[0].message.content)
from openai import OpenAIfrom portkey_ai import PORTKEY_GATEWAY_URL# 1. Install: pip install openai portkey-ai# 2. Add @databricks provider in model catalog# 3. Use it:client = OpenAI( api_key="PORTKEY_API_KEY", # Portkey API key base_url=PORTKEY_GATEWAY_URL)response = client.chat.completions.create( model="@databricks/databricks-meta-llama-3-1-70b-instruct", messages=[{"role": "user", "content": "Say this is a test"}])print(response.choices[0].message.content)
import OpenAI from "openai"import { PORTKEY_GATEWAY_URL } from "portkey-ai"// 1. Install: npm install openai portkey-ai// 2. Add @databricks provider in model catalog// 3. Use it:const client = new OpenAI({ apiKey: "PORTKEY_API_KEY", // Portkey API key baseURL: PORTKEY_GATEWAY_URL})const response = await client.chat.completions.create({ model: "@databricks/databricks-meta-llama-3-1-70b-instruct", messages: [{ role: "user", content: "Say this is a test" }]})console.log(response.choices[0].message.content)
# 1. Add @databricks provider in model catalog# 2. Use it:curl https://api.portkey.ai/v1/chat/completions \ -H "Content-Type: application/json" \ -H "x-portkey-api-key: $PORTKEY_API_KEY" \ -d '{ "model": "@databricks/databricks-meta-llama-3-1-70b-instruct", "messages": [ { "role": "user", "content": "Say this is a test" } ] }'
Tip: You can also set provider="@databricks" in Portkey() and use just model="databricks-meta-llama-3-1-70b-instruct" in the request.
Generate embeddings using Databricks-hosted embedding models:
from portkey_ai import Portkeyportkey = Portkey(api_key="PORTKEY_API_KEY")response = portkey.embeddings.create( model="@databricks/databricks-bge-large-en", input="The quick brown fox jumps over the lazy dog")print(response.data[0].embedding[:5])
import Portkey from 'portkey-ai'const portkey = new Portkey({ apiKey: "PORTKEY_API_KEY"})const response = await portkey.embeddings.create({ model: "@databricks/databricks-bge-large-en", input: "The quick brown fox jumps over the lazy dog"})console.log(response.data[0].embedding.slice(0, 5))
curl https://api.portkey.ai/v1/embeddings \ -H "Content-Type: application/json" \ -H "x-portkey-api-key: $PORTKEY_API_KEY" \ -d '{ "model": "@databricks/databricks-bge-large-en", "input": "The quick brown fox jumps over the lazy dog" }'
Use the OpenAI Responses API format with Databricks models:
from portkey_ai import Portkeyportkey = Portkey(api_key="PORTKEY_API_KEY")response = portkey.responses.create( model="@databricks/databricks-meta-llama-3-1-70b-instruct", input="Tell me a three sentence bedtime story about a unicorn.")print(response)
import Portkey from 'portkey-ai'const portkey = new Portkey({ apiKey: "PORTKEY_API_KEY"})const response = await portkey.responses.create({ model: "@databricks/databricks-meta-llama-3-1-70b-instruct", input: "Tell me a three sentence bedtime story about a unicorn."})console.log(response)
curl https://api.portkey.ai/v1/responses \ -H "Content-Type: application/json" \ -H "x-portkey-api-key: $PORTKEY_API_KEY" \ -d '{ "model": "@databricks/databricks-meta-llama-3-1-70b-instruct", "input": "Tell me a three sentence bedtime story about a unicorn." }'