Skip to main content

Open Models Inference

Open model inference endpoints allow interacting with models using their unique identifier directly in the URL path. This is particularly useful for finetuned models or custom open-source models deployed on the Knowledgator platform.

Available Endpoints​

  • Generic Prediction - Send a generic POST request to the model's base endpoint (/inference/{model_id}/).
  • Method-based Inference - Call a specific method on the model (/inference/{model_id}/{method}/).

SDK Usage​

💡 Dedicated SDK Guides: See Python SDK | TypeScript SDK

TypeScript/JavaScript​

In the JavaScript SDK, use the model() method to create a model-specific client.

import { createClient } from '@knowledgator/typescript-sdk';

const kg = createClient('your-api-key');

// Initialize the model client
const model = kg.model('your-model-id');

// Generic prediction (POST /inference/{model_id}/)
const response = await model.predict({
input: 'text to process'
});

// Shorthand for method-based inference
const generator = kg.model('your-model-id', 'generate');

// Calls /inference/your-model-id/generate/
const result = await generator.predict({
prompt: 'Tell me a story about a brave knight.'
});

Python​

You can access an open model using the model() method on the Knowledgator client.

from knowledgator import Knowledgator

kg = Knowledgator(api_key="your-api-key")

# Initialize the model client
model = kg.model("your-model-id")

# Generic prediction (POST /inference/{model_id}/)
response = model.predict({
"input": "text to process"
})

# Shorthand for method-based inference (POST /inference/{model_id}/{method}/)
# You can specify a default method during initialization
generator = kg.model("your-model-id", method="generate")

# Calls /inference/your-model-id/generate/
response = generator.predict({
"prompt": "Tell me a story about a brave knight."
})

Python Requests​

import requests

model_id = "your-model-id"
url = f"https://api.platform.knowledgator.com/inference/{model_id}/"
headers = {
"Content-Type": "application/json",
"KnowledgatorAPI-Key": "YOUR_API_KEY"
}
payload = {
"input": "text processed via direct request"
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

cURL​

curl -X POST https://api.platform.knowledgator.com/inference/your-model-id/ \
-H "Content-Type: application/json" \
-H "KnowledgatorAPI-Key: YOUR_API_KEY" \
-d '{
"input": "text processed via cURL"
}'