Skip to main content

Integrating Applications

Routes & Unified Endpoints

Overview

Javelin provides a powerful routing system that allows you to seamlessly integrate your LLM applications with various AI providers while adding security, monitoring, and guardrails. This guide explains how to integrate your applications with Javelin and leverage its unified endpoint architecture.

Javelin Integration

Getting Started with Javelin Integration

Integrating your applications with Javelin involves three simple steps:

  1. Configure Javelin Routes: Set up routes in your Javelin gateway to direct traffic to specific models and providers.
  2. Update API Endpoints: Change your application's API endpoints to point to Javelin instead of directly to providers.
  3. Add Authentication: Include your Javelin API key alongside your provider API keys.

Prerequisites

Before you begin integration, ensure you have:

  • A Javelin account with API access
  • Your Javelin API key
  • API keys for the LLM providers you plan to use (OpenAI, Azure, etc.)

Leveraging the Javelin Platform

The core usage of Javelin is to define routes, and then to define what to do at each route. Rather than having your LLM Applications (like Co-Pilot apps, chatbots, etc.) individually and directly point to the LLM Vendor & Model (like OpenAI, Gemini, etc.), configure the provider/model endpoint to be your Javelin endpoint.

This architecture ensures that all applications that leverage AI Models will route their requests through the Javelin gateway, providing:

  • Centralized security and access control
  • Consistent monitoring and observability
  • Standardized guardrails and safety measures
  • Simplified provider switching and fallback options

Javelin supports all the latest models and providers, so you don't have to make any changes to your application or how requests to models are sent.

See the Javelin Configuration section for details on how to set up routes on the gateway to different models and providers.

For programmatic integration, see the Python SDK documentation for details on how you can easily embed Javelin within your AI applications.

Unified Endpoints Architecture

The Unified Endpoints provide a consistent API interface that abstracts the provider-specific details of various AI services. This standardization offers several key benefits:

Key Benefits

  1. Single Entry Points: Instead of routing to different URLs for each provider, you call standardized "unified" endpoints with specific route parameters or path segments.

  2. Consistent Request/Response Shapes: All requests follow a uniform structure (for example, a JSON object with a prompt, messages, or input for embeddings). The service then translates it to each provider's specific API format as needed.

  3. Provider Flexibility: Switch between providers without changing your application code.

  4. Simplified Authentication: Use a consistent authentication pattern across all providers.

Endpoint Types Overview

Javelin supports four main types of endpoints:

Endpoint TypeDescriptionUse Case
OpenAI-CompatibleStandard OpenAI API formatGeneral text generation, chat, and embeddings
Azure OpenAIAzure-specific deployment modelEnterprise Azure OpenAI deployments
AWS BedrockAWS-specific model routingAWS Bedrock model access
QueryGeneric route-based accessCustom routing configurations

Endpoint Breakdown

1. OpenAI-Compatible Endpoints

These endpoints mirror the standard OpenAI API methods. They allow you to perform common AI tasks such as generating text completions, handling chat-based requests, or producing embeddings.

Available Endpoints

EndpointMethodDescription
/completionsPOSTRequest text completions from the provider
/chat/completionsPOSTRequest chat-based completions (ideal for conversational interfaces)
/embeddingsPOSTGenerate embeddings for provided text data

Example: Chat Completions

curl -X POST "https://your-javelin-domain.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YOUR_LLM_API_KEY" \
-H "X-Javelin-apikey: $YOUR_JAVELIN_API_KEY" \
-H "X-Javelin-route: $JAVELIN_ROUTE_OPENAI_COMPATIBLE" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me about Javelin."}
],
"temperature": 0.7,
"max_tokens": 150
}'

Note: Replace your-javelin-domain.com with your actual Javelin API domain, and insert your actual API keys.

Provider Compatibility

You can use these endpoints with any OpenAI-compatible provider by specifying the appropriate model name. Supported providers include:

  • OpenAI
  • Azure OpenAI
  • Mistral AI
  • Anthropic (Claude)
  • Cohere
  • DeepSeek
  • And more

2. Azure OpenAI API Endpoints

For providers using Azure's deployment model, endpoints include additional parameters for deployment management.

Available Endpoints

EndpointMethodDescription
/openai/deployments/{deployment}/completionsPOSTRequest text completions from Azure deployment
/openai/deployments/{deployment}/chat/completionsPOSTRequest chat-based completions from Azure deployment
/openai/deployments/{deployment}/embeddingsPOSTGenerate embeddings from Azure deployment

Path Parameters

  • providername: The Azure OpenAI provider identifier
  • deployment: The deployment ID configured in Azure

Example: Azure Chat Completions

curl -X POST "https://your-javelin-domain.com/v1/deployments/my-deployment/chat/completions?api-version=2024-02-15-preview" \
-H "Content-Type: application/json" \
-H "api-key: $YOUR_AZURE_OPENAI_API_KEY" \
-H "X-Javelin-apikey: $YOUR_JAVELIN_API_KEY" \
-H "X-Javelin-route: $JAVELIN_ROUTE_AZURE_OPENAI" \
-d '{
"messages": [
{"role": "user", "content": "Tell me a story"}
],
"max_tokens": 50
}'

3. AWS Bedrock API Endpoints

For AWS Bedrock–style providers, the endpoints use a slightly different URL pattern to accommodate model versioning and extended routing.

Available Endpoints

EndpointMethodDescription
/model/{routename}/{apivariation}POSTRoute requests to a specific AWS Bedrock model and API variation

Path Parameters

  • routename: The model or route name (identifies a specific AWS Bedrock model)
  • apivariation: A parameter to indicate the API variation ("Invoke", "Invoke-Stream", "Invoke-With-Response-Stream", "Converse", "Converse-Stream") or version

Example: AWS Bedrock Model Request

curl -X POST "https://your-javelin-domain.com/v1/model/anthropic.claude-3-sonnet-20240229-v1:0/invoke" \
-H "Content-Type: application/json" \
-H "X-Javelin-apikey: $YOUR_JAVELIN_API_KEY" \
-H "X-Javelin-route: $JAVELIN_ROUTE_BEDROCK" \
-d '{
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 100,
"messages": [
{
"content": "What is the capital of France?",
"role": "user"
}
]
}'

4. Query Endpoints

These endpoints allow direct querying of predefined routes, bypassing provider-specific names when a generic and customizable route configuration is desired.

Available Endpoints

EndpointMethodDescription
/query/{routename}POSTExecute a query against a specific route

Path Parameters

  • routename: The route with one or more models based on the configured policies and route configurations

Example: Query Route

First, create a route as shown in the Create Route section.

Once you have created a route, you can query it using the following curl command:

curl 'https://your-api-domain.com/v1/query/your_route_name' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer $YOUR_OPENAI_API_KEY' \
-H 'X-Javelin-apikey: $YOUR_JAVELIN_API_KEY' \
-d '{
"model": "gpt-3.5-turbo",
"messages": [
{"role": "user", "content": "SANFRANCISCO is located in?"}
],
"temperature": 0.8
}'

Important: Make sure to replace your_route_name, YOUR_OPENAI_API_KEY, and YOUR_JAVELIN_API_KEY with your actual values.

SDK Integration Examples

Python

pip install javelin-sdk
Query Route with Javelin SDK
from javelin_sdk import JavelinClient, JavelinConfig, Route
import os

javelin_api_key = os.getenv('JAVELIN_API_KEY')
llm_api_key = os.getenv("OPENAI_API_KEY")

# Create Javelin configuration
config = JavelinConfig(
base_url="https://your-api-domain.com",
javelin_api_key=javelin_api_key,
llm_api_key=llm_api_key
)

# Create Javelin client
client = JavelinClient(config)

# Route name to get is {routename} e.g., sampleroute1
query_data = {
"messages": [
{
"role": "system",
"content": "Hello, you are a helpful scientific assistant."
},
{
"role": "user",
"content": "What is the chemical composition of sugar?"
}
],
"temperature": 0.8
}

# Now query the route, for async use 'await client.aquery_route("sampleroute1", query_data)'
response = client.query_route("sampleroute1", query_data)
print(response.model_dump_json(indent=2))

JavaScript/TypeScript

npm install openai
OpenAI API Integration Example
import OpenAI from "openai";

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: "https://your-api-domain.com/v1/query/{your_route_name}",
defaultHeaders: {
"X-Javelin-apikey": `${process.env.JAVELIN_API_KEY}`
},
});

async function main() {
const completion = await openai.chat.completions.create({
messages: [{ role: "system", content: "You are a helpful assistant." }],
model: "gpt-3.5-turbo",
});

console.log(completion.choices[0]);
}

main();

Authentication

All requests to Javelin endpoints require authentication using:

  1. Javelin API Key: Passed in the X-Javelin-apikey header
  2. Model Provider API Key: Passed in the Authorization header (mostly)

Example:

curl -X POST "https://your-javelin-domain.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_PROVIDER_API_KEY" \
-H "X-Javelin-apikey: YOUR_JAVELIN_API_KEY" \
-d '{ ... }'

Javelin Headers

When integrating with Javelin, you can customize behavior and routing by using the following custom headers in your requests:

HeaderRequiredDescription
X-Javelin-apikey✅ YesYour Javelin API key. Used to authenticate requests to the Javelin platform.
X-Javelin-virtualapikeyOptionalA secure placeholder for provider API keys. Instead of exposing real provider credentials, you can pass a virtual key ID; Javelin will resolve it to the real secret stored in your vault. This adds security, supports credential rotation, and simplifies integration.
X-Javelin-route✅ Yes (for unified endpoints)Specifies the Javelin route name to determine model, provider, fallback policies, and guardrails.
X-Javelin-modelOptionalAllows overriding the default model at runtime (e.g., gpt-4, claude-3-sonnet) for OpenAI-compatible or Bedrock-like APIs.
X-Javelin-providerOptionalUse this to override or specify a provider URL (e.g., https://api.openai.com/v1). Useful in cases where your route supports multiple backends.

⚠️ Some headers are optional depending on the type of endpoint (OpenAI-compatible, Bedrock, Azure, etc.), but using X-Javelin-apikey and X-Javelin-route is standard for most integrations.

Error Handling

Javelin returns standard HTTP status codes and error messages. Common errors include:

Status CodeDescriptionCommon Causes
400Bad RequestInvalid request format or parameters
401UnauthorizedMissing or invalid API keys
404Not FoundEndpoint or route doesn't exist
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer-side issue

Example error response:

{
"error": {
"code": "401",
"message": "Invalid request: model parameter is required"
}
}

Best Practices

  1. Use Environment Variables: Store API keys in environment variables, not in code.
  2. Implement Retry Logic: Add retry mechanisms for transient errors.
  3. Set Timeouts: Configure appropriate timeouts for your application needs.
  4. Monitor Usage: Use Javelin's monitoring features to track usage and costs.
  5. Test Thoroughly: Test your integration with different providers and models.

Troubleshooting

Common Issues

  1. Authentication Errors

    • Verify both provider and Javelin API keys are correct
    • Check that keys are passed in the correct headers
  2. Endpoint Not Found

    • Confirm the endpoint URL is correct
    • Verify the route exists in your Javelin configuration
  3. Request Format Errors

    • Ensure your JSON payload matches the expected format
    • Check for required fields specific to the model you're using
  4. Rate Limiting

    • Implement exponential backoff for retries
    • Consider adjusting your request patterns