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:- A Gloo AI Studio account
- Your Client ID and Client Secret from the API Credentials page
- Authentication setup - Complete the Authentication Tutorial first
Choose Your Routing Strategy
Completions V2 offers three routing modes:| Mode | Use Case | Parameter |
|---|---|---|
| AI Core (Recommended) | Let Gloo AI automatically select the best model | "auto_routing": true |
| AI Core Select | Choose a provider family, let Gloo pick the model | "model_family": "anthropic" |
| AI Select | Specify an exact model | "model": "gloo-openai-gpt-5-mini" |
Example 1: Auto-Routing (Recommended)
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:openai, anthropic, google, open source
Example 3: Direct Model Selection
Choose a specific model for full control:Understanding the Response
V2 responses include additional routing metadata:routing_mechanism: How the model was selected (auto_routing,model_family, ordirect_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 token retrieval, expiration checking, and all three routing strategies into a single, runnable script for each language. Each example demonstrates auto-routing, model family selection, and direct model selection. You’ll want to first set up your environment variables in either an.env file:
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:- Completions V2 Guide - Full API documentation
- Supported Model IDs - All available models
- Tool Use - Function calling with completions
- Chat Tutorial - Stateful chat interactions

