Skip to content

Comments

Add product headers to default model providers#118

Merged
MohamedSabthar merged 7 commits intoballerina-platform:mainfrom
SasinduDilshara:add-headers
Feb 19, 2026
Merged

Add product headers to default model providers#118
MohamedSabthar merged 7 commits intoballerina-platform:mainfrom
SasinduDilshara:add-headers

Conversation

@SasinduDilshara
Copy link
Contributor

@SasinduDilshara SasinduDilshara commented Feb 16, 2026

Purpose

Fixes: wso2/product-ballerina-integrator#2456

Examples

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility

Summary

Adds consistent request headers to the default model provider to improve tracing and observability of AI model requests.

Changes

  • Include HTTP headers in model provider requests:
    • x-product: "bi" (applies to chat and embedding requests)
    • x-usage-context: "model_provider_chat" for chat completions
    • x-usage-context: "model_provider_embeddings" for embedding requests
  • Code updates:
    • ballerina/default-model-provider-utils.bal — pass headers on chat completion calls initiated by utility functions
    • ballerina/model-provider.bal — include headers on /chat/completions requests
    • ballerina/embedding-provider.bal — include headers on /embeddings requests in embed() and batchEmbed()
  • Tests:
    • ballerina-tests/tests/wso2-model-provider-test-services.bal — test resource signature updated to accept the new headers and assertions added to validate the expected header values alongside existing payload checks

Impact

Enables consistent request-level metadata for model provider interactions to support tracing and monitoring. Existing request construction, response handling, and error flows are unchanged aside from the added headers. Tests were updated to assert presence and expected values of the new headers.

@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Added x-product: "bi" and x-usage-context HTTP headers to chat and embedding POST requests in the model provider code and updated the test service to accept and assert those headers. No other control-flow or error-handling changes.

Changes

Cohort / File(s) Summary
Test Service Header Validation
ballerina-tests/tests/wso2-model-provider-test-services.bal
Updated resource signature to accept @http:Header string x-product and @http:Header string x-usage-context; added runtime assertions verifying x-product == "bi" and x-usage-context == "model_provider_chat".
Model Provider Chat Header Additions
ballerina/default-model-provider-utils.bal, ballerina/model-provider.bal
Chat completion POST requests updated to include headers: x-product: "bi" and x-usage-context: "model_provider_chat". No other logic changes.
Embedding Provider Header Addition
ballerina/embedding-provider.bal
Embedding POST requests (single and batch) updated to include headers: x-product: "bi" and x-usage-context: "model_provider_embeddings".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nudged two headers into the stream,

x-product and context in a tiny gleam,
Chats and embeds now hop in line,
Traces hum softly, tidy and fine,
A rabbit claps—headers stitched with cream.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add product headers to default model providers' clearly and concisely summarizes the main change: adding HTTP headers to model provider requests.
Linked Issues check ✅ Passed All coding requirements from issue #2456 are met: x-product and x-usage-context headers are added to default model provider requests across multiple files.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue requirements; no unrelated modifications are present in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@ballerina/embedding-provider.bal`:
- Around line 90-93: The batchEmbed() call is missing the tracing headers added
in embed(); update batchEmbed() so its call to
self.embeddingClient->/embeddings.post includes the same headers dictionary
("x-product": "bi", "x-usage-context": "model_provider_embeddings") as used in
embed(), ensuring both functions call the same endpoint with identical tracing
headers; locate batchEmbed() and modify the embeddings POST invocation to pass
headers = { "x-product": "bi", "x-usage-context": "model_provider_embeddings" }.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds tracking headers to WSO2 intelligence API calls to identify the product ("bi") and usage context (e.g., "model_provider_chat" or "model_provider_embeddings"). The headers enable better monitoring and analytics for API usage across different contexts.

Changes:

  • Added x-product and x-usage-context headers to chat completions API calls in model provider and utility functions
  • Added the same headers to the embeddings API call in the embedding provider's embed method
  • Added test assertions to verify the headers are correctly sent with API requests

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
ballerina/model-provider.bal Added tracking headers to chat completions POST request
ballerina/embedding-provider.bal Added tracking headers to embeddings POST request in embed method
ballerina/default-model-provider-utils.bal Added tracking headers to chat completions POST request in utility function
ballerina-tests/tests/wso2-model-provider-test-services.bal Added header parameter extraction and assertions in test service

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.06%. Comparing base (327f14c) to head (3d85098).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
ballerina/embedding-provider.bal 0.00% 6 Missing ⚠️
ballerina/model-provider.bal 0.00% 3 Missing ⚠️

❌ Your project status has failed because the head coverage (56.06%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #118      +/-   ##
============================================
+ Coverage     52.47%   56.06%   +3.59%     
- Complexity        0      238     +238     
============================================
  Files            60       80      +20     
  Lines          4444     5595    +1151     
  Branches        924     1098     +174     
============================================
+ Hits           2332     3137     +805     
- Misses         2068     2311     +243     
- Partials         44      147     +103     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SasinduDilshara SasinduDilshara changed the title Add headers Add product headers to default model providers Feb 17, 2026
@MohamedSabthar MohamedSabthar merged commit e9266bd into ballerina-platform:main Feb 19, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Product and Method Headers to Requests for the Default Model Provider

3 participants