Skip to main content
This guide provides a practical, step-by-step tutorial for using the Gloo AI Completions V2 API with its powerful routing features.
Why V2? Completions V2 offers auto-routing for optimal model selection, model family preferences, and tradition-aware responses—all while maintaining compatibility with the standard chat completions format.

Prerequisites

Before starting, ensure you have:

Choose Your Routing Strategy

Completions V2 offers three routing modes:
Let Gloo AI analyze your query and automatically select the optimal model:

Example 2: Model Family Selection

Specify a provider family and let Gloo AI pick the best model within that family:
Available model families: openai, anthropic, google, open source

Example 3: Direct Model Selection

Choose a specific model for full control:
See the Supported Model IDs page for all available models.

Understanding the Response

V2 responses include additional routing metadata:
Key metadata fields:
  • routing_mechanism: How the model was selected (auto_routing, model_family, or direct_model_selection)
  • routing_tier: The complexity tier determined by auto-routing (tier_1, tier_2, tier_3)
  • routing_confidence: Confidence score for the routing decision (0.0-1.0)
  • tradition: The theological perspective applied (if specified)

Streaming Responses

Enable streaming for real-time responses:

Complete Examples

The following examples combine all three routing strategies into a single, runnable script for each language. You’ll want to first set up your environment variables in either an .env file:
Or export them in your shell for Go and Java:

Working Code Sample

View Complete Code

Clone or browse the complete working examples for all 6 languages (JavaScript, TypeScript, Python, PHP, Go, Java) with setup instructions.

Next Steps

Now that you understand the Completions V2 API, explore:
  1. Completions V2 Guide - Full API documentation
  2. Supported Model IDs - All available models
  3. Tool Use - Function calling with completions
  4. Chat Tutorial - Stateful chat interactions