Integrate BytePlus ModelArk models with Portkey’s AI Gateway
Portkey provides a robust and secure gateway to integrate various Large Language Models (LLMs) into applications, including BytePlus ModelArk models.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 @byteplus provider in model catalog# 3. Use it:portkey = Portkey(api_key="PORTKEY_API_KEY")response = portkey.chat.completions.create( model="@byteplus/ep-m-your-endpoint-id", 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 @byteplus provider in model catalog// 3. Use it:const portkey = new Portkey({ apiKey: "PORTKEY_API_KEY"})const response = await portkey.chat.completions.create({ model: "@byteplus/ep-m-your-endpoint-id", 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 @byteplus 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="@byteplus/ep-m-your-endpoint-id", 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 @byteplus 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: "@byteplus/ep-m-your-endpoint-id", messages: [{ role: "user", content: "Say this is a test" }]})console.log(response.choices[0].message.content)
# 1. Add @byteplus 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": "@byteplus/ep-m-your-endpoint-id", "messages": [ { "role": "user", "content": "Say this is a test" } ] }'
Tip: You can also set provider="@byteplus" in Portkey() and use just model="ep-m-your-endpoint-id" in the request.
Generate multimodal embeddings using BytePlus ModelArk:
from portkey_ai import Portkeyportkey = Portkey(api_key="PORTKEY_API_KEY")response = portkey.embeddings.create( model="@byteplus/ep-m-your-embedding-endpoint", 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: "@byteplus/ep-m-your-embedding-endpoint", 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": "@byteplus/ep-m-your-embedding-endpoint", "input": "The quick brown fox jumps over the lazy dog" }'
Generate images using BytePlus ModelArk image models:
from portkey_ai import Portkeyportkey = Portkey(api_key="PORTKEY_API_KEY")image = portkey.images.generate( model="@byteplus/ep-m-your-image-endpoint", prompt="A serene landscape with mountains and a lake at sunset", size="1024x1024")print(image.data[0].url)
import Portkey from 'portkey-ai'const portkey = new Portkey({ apiKey: "PORTKEY_API_KEY"})const image = await portkey.images.generate({ model: "@byteplus/ep-m-your-image-endpoint", prompt: "A serene landscape with mountains and a lake at sunset", size: "1024x1024"})console.log(image.data[0].url)
curl https://api.portkey.ai/v1/images/generations \ -H "Content-Type: application/json" \ -H "x-portkey-api-key: $PORTKEY_API_KEY" \ -d '{ "model": "@byteplus/ep-m-your-image-endpoint", "prompt": "A serene landscape with mountains and a lake at sunset", "size": "1024x1024" }'
Use the OpenAI Responses API format with BytePlus models:
from portkey_ai import Portkeyportkey = Portkey(api_key="PORTKEY_API_KEY")response = portkey.responses.create( model="@byteplus/ep-m-your-endpoint-id", 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: "@byteplus/ep-m-your-endpoint-id", 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": "@byteplus/ep-m-your-endpoint-id", "input": "Tell me a three sentence bedtime story about a unicorn." }'
Responses API reference
Full Responses API docs — streaming, tools, instructions, and more