Skip to main content
This tutorial builds a resource recommender on the Gloo AI Recommendations API: publisher-scoped recommendations, snippet previews for richer displays, and discovery across the Gloo affiliate publisher network. Want the concepts first? Read the Concepts guide and Affiliate Recommendations, or the Recommendations lesson in the AI Learning Center. Unlike keyword search, the Recommendations API ranks content by semantic relevance to a user’s query, making it ideal for “You might also like” panels, related-resource sections, and cross-publisher content discovery.
The Recommendations API returns ranked content items from your publisher’s collection or the Gloo affiliate network. It is optimized for recommendation UI patterns, not open-ended search.

What you’ll build

A resource recommender, one endpoint per step:

Prerequisites

You need:

Working Code Sample

Follow along with complete working examples in all 6 languages (JavaScript, TypeScript, Python, PHP, Go, Java). Includes a proxy server and browser-based frontend for each language.
The code snippets in this tutorial are simplified and self-contained — designed for readability and easy copy-paste. The cookbook examples use a modular architecture plus production niceties. Both implement the same APIs and patterns.

The Recommendations API at a glance

The Item Recommendations guide and Affiliate Recommendations guide cover every option. Expand a panel for the parameters and response fields this tutorial uses.
Both publisher endpoints take the same parameters (query and collection are required):
The affiliate endpoint searches across the full Gloo publisher network so no collection or tenant is required:
Publisher endpoints return an array of items. Each item includes a uuids array with the matched snippet and its relevance metadata:
Key fields:
  • uuids[0].certainty — Relevance score (0–1, higher = more relevant)
  • uuids[0].ai_title — AI-generated section title for the matched snippet
  • uuids[0].item_summary — AI-generated summary of the item
  • uuids[0].snippet — Full snippet text (verbose endpoint only)
The affiliate endpoint returns a flatter structure without uuids, adding tradition and item_subtitle fields instead.

Step 1: Publisher Recommendations

The base endpoint returns ranked items from your publisher’s collection with no snippet text, ideal for clean list UIs.
A successful call returns up to 5 items with metadata such as the title, summary, and relevance score:
Fields like Summary and Section may not appear for every item: they’re AI-generated during ingestion, so older or minimally processed content may return only Title, Author, and Relevance.
Getting no results? Work through these in order:
  1. Test your query in the Search Playground — if nothing shows there, your content may not be indexed yet.
  2. Try a different query that you know returns results in the Playground.
  3. If the Playground returns results but your code doesn’t, lower certainty_threshold from 0.75 to 0.5 to match the Playground’s default.

Step 2: Recommendations with Snippet Previews

The verbose endpoint adds full snippet text to each result, for preview cards that show a passage alongside the title. The only change from Step 1 is the endpoint URL and reading uuids[0].snippet from the response.
Same as Step 1, with a Preview line added for each item:

Step 3: Affiliate Network Discovery

The affiliate endpoint surfaces content from across the entire Gloo publisher network, not just your own collection. Use it to power “Explore More” sections that introduce users to resources from other publishers. Two key differences from the publisher endpoints:
  • No collection or tenant in the request — the search spans the full affiliate network
  • Flat response structure — items have tradition and item_subtitle fields instead of uuids

Complete code

View Complete Code

Clone or browse the complete working examples for all 6 languages (JavaScript, TypeScript, Python, PHP, Go, Java) with setup instructions, proxy servers, and a browser-based frontend.

What’s Included

Each language implementation provides:
  • auth — Shared API key configuration
  • config — Centralized configuration (URLs, env vars)
  • recommend_base — Publisher recommendations CLI (metadata only)
  • recommend_verbose — Publisher recommendations CLI (with snippet text)
  • recommend_affiliates — Affiliate network discovery CLI
  • server — Proxy server exposing REST endpoints for the frontend

Run the cookbook examples

Each step has a ready-to-run script in the cookbook. Set up with the Step 1 commands, then run the later steps from the same directory:
1

Publisher recommendations

The cookbook includes a ready-to-run basic search script for each language:
2

Snippet previews

3

Affiliate discovery

The cookbook includes a browser-based frontend that connects to a proxy server, letting you visualize all three recommendation modes. The proxy server keeps your credentials secure on the server side (see API Key Security).Architecture
The proxy server exposes three endpoints:
  • POST /api/recommendations/base — Publisher recommendations (metadata only)
  • POST /api/recommendations/verbose — Publisher recommendations (with snippet previews)
  • POST /api/recommendations/affiliates — Affiliate network discovery
Start the Proxy ServerEach language includes a proxy server. Start one:
Then open http://localhost:3000 in your browser.Publisher RecommendationsEnter a query, choose how many items to return, and optionally enable Verbose mode to show snippet previews alongside each result:
Publisher recommendation results showing content cards with relevance scores and optional snippet previews
Affiliate Network DiscoveryThe Explore More panel fires automatically alongside your publisher results, surfacing related content from across the Gloo network:
Affiliate recommendation results showing resources from across the Gloo publisher network
The frontend is language-agnostic — the same HTML/JS works with any language’s proxy server. This is one approach; customize for your branding and framework.

Troubleshooting

  • certainty_threshold too strict: This tutorial sends 0.75, which filters out lower-confidence matches. Lower it to 0.5 (the API default) to broaden results.
  • Content not indexed: Test the same query in the Search Playground. If content appears there, your API parameters are correct.
  • Wrong tenant: Results are scoped to your publisher. Verify the tenant name matches your publisher in Organizations.
  • You can only access your own publisher’s content via the publisher endpoints.
  • Verify your API key is correct and has not been revoked.
  • The affiliate endpoint has broader access — a 403 there indicates an API key issue.
  • Not all content is available in the affiliate network. Publishers must opt in.
  • Try a broader or different query to confirm the endpoint is working.
  • If your API key is rejected, check it hasn’t been revoked (see Authentication Tutorial).
  • Ensure you’re using Bearer {api_key} in the Authorization header.

Next steps

Base Recommendations API Reference

Endpoint docs for recommendation results that return item metadata only.

Verbose Recommendations API Reference

Endpoint docs for recommendation results that include snippet previews.

Affiliate Referenced Items API Reference

Explore cross-publisher affiliate discovery for related content.

Upload Files

Add more content to your Data Engine for richer recommendations.