Portkey provides a robust and secure gateway to facilitate the integration of various models into your applications, including Jina AI embedding & reranker models.
With Portkey, you can take advantage of features like fast AI gateway access, observability, and more, all while ensuring the secure management of your API keys through a virtual key system.
Portkey SDK Integration with Jina AI Models
Portkey provides a consistent API to interact with models from various providers. To integrate Jina AI with Portkey:
1. Install the Portkey SDK
Add the Portkey SDK to your application to interact with Jina AI’s API through Portkey’s gateway.
npm install --save portkey-ai
npm install --save portkey-ai
2. Initialize Portkey with the Virtual Key
To use JinaAI with Portkey, get your API key from here, then add it to Portkey to create the virtual key.
import Portkey from 'portkey-ai'
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
virtualKey: "JINA_AI_VIRTUAL_KEY" // Your Jina AI Virtual Key
})
import Portkey from 'portkey-ai'
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
virtualKey: "JINA_AI_VIRTUAL_KEY" // Your Jina AI Virtual Key
})
from portkey_ai import Portkey
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="JINA_AI_VIRTUAL_KEY" # Replace with your virtual key for Jina AI
)
3. Invoke Embeddings with Jina AI
Use the Portkey instance to send your embeddings requests to Jina AI. You can also override the virtual key directly in the API call if needed.
const embeddings = await portkey.embeddings.create({
input: "embed this",
model: "jina-embeddings-v2-base-es",
});
const embeddings = await portkey.embeddings.create({
input: "embed this",
model: "jina-embeddings-v2-base-es",
});
embeddings = portkey.embeddings.create(
input = "embed this",
model = "jina-embeddings-v2-base-de"
)
Using Jina AI Reranker Models
Portkey also supports the Reranker models by Jina AI through the REST API.
curl https://api.portkey.ai/v1/rerank \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $JINA_AI_API_KEY" \
-H "x-portkey-provider: jina" \
-d '{
"model": "jina-reranker-v1-base-en",
"query": "Organic skincare products for sensitive skin",
"documents": [
"Eco-friendly kitchenware for modern homes",
"Biodegradable cleaning supplies for eco-conscious consumers",
"Organic cotton baby clothes for sensitive skin"
],
"top_n": 2
}'
curl https://api.portkey.ai/v1/rerank \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $JINA_AI_API_KEY" \
-H "x-portkey-provider: jina" \
-d '{
"model": "jina-reranker-v1-base-en",
"query": "Organic skincare products for sensitive skin",
"documents": [
"Eco-friendly kitchenware for modern homes",
"Biodegradable cleaning supplies for eco-conscious consumers",
"Organic cotton baby clothes for sensitive skin"
],
"top_n": 2
}'
Supported Models
Portkey works with all the embedding & reranker models offered by Jina AI. You can browse the full list of Jina AI models here.
Next Steps
The complete list of features supported in the SDK are available on the link below.
You’ll find more information in the relevant sections:
- Add metadata to your requests
- Add gateway configs to your Jina AI requests
- Tracing Jina AI requests
- Setup a fallback from OpenAI Embeddings to Jina AI