Skip to content

Add TypeScript SDK client for listing provider models#1855

Open
Uday-sidagana wants to merge 1 commit into
langflow-ai:mainfrom
Uday-sidagana:Jun-sdk-ts-models-client
Open

Add TypeScript SDK client for listing provider models#1855
Uday-sidagana wants to merge 1 commit into
langflow-ai:mainfrom
Uday-sidagana:Jun-sdk-ts-models-client

Conversation

@Uday-sidagana

@Uday-sidagana Uday-sidagana commented Jun 12, 2026

Copy link
Copy Markdown

Adds TypeScript SDK support for listing provider models via the existing public /v1/models/{provider} endpoint. This brings the TypeScript SDK to parity with the Python SDK, which already exposes client.models.list(provider).

What changed

  • Added client.models.list(provider).
  • Added ModelsClient.
  • Added ModelOption and ModelsResponse types.
  • Exported the new models client and types.
  • Added a README example.
  • Added an integration test for client.models.list("openai").

Summary by CodeRabbit

Release Notes

  • New Features

    • New Models API allows developers to retrieve available language models and embedding models for a given provider.
  • Documentation

    • TypeScript SDK README updated with a new Models section, including example code showing how to list models.
  • Tests

    • Integration test added to verify Models API functionality and response structure.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR adds a new Models client to the TypeScript SDK. ModelsClient provides a list(provider) method to fetch available language and embedding models per provider from the /api/v1/models/{provider} endpoint. The feature includes new type contracts, the client implementation, integration into the main OpenRAGClient, public exports, and integration tests.

Changes

Models Client Feature

Layer / File(s) Summary
Models type contracts
sdks/typescript/src/types.ts
Defines ModelOption (value, label, optional default) and ModelsResponse (language_models and embedding_models arrays).
ModelsClient implementation
sdks/typescript/src/models.ts
Implements ModelsClient with list(provider: string): Promise<ModelsResponse> method that calls /api/v1/models/{provider}, parses JSON, and normalizes empty arrays.
OpenRAGClient integration
sdks/typescript/src/client.ts
Adds readonly models: ModelsClient property to OpenRAGClient and instantiates it alongside other sub-clients.
Public API exports
sdks/typescript/src/index.ts
Exports ModelsClient, ModelOption, and ModelsResponse to the public TypeScript surface.
Documentation and integration tests
sdks/typescript/README.md, sdks/typescript/tests/integration.test.ts
Adds README example calling client.models.list("openai") and skipped integration test validating response structure.

Sequence Diagram

sequenceDiagram
  participant Consumer
  participant OpenRAGClient
  participant ModelsClient
  participant APIEndpoint
  Consumer->>OpenRAGClient: instantiate
  OpenRAGClient->>ModelsClient: new ModelsClient(this)
  Consumer->>ModelsClient: list("openai")
  ModelsClient->>APIEndpoint: GET /api/v1/models/openai
  APIEndpoint-->>ModelsClient: {language_models, embedding_models}
  ModelsClient->>ModelsClient: normalize to arrays
  ModelsClient-->>Consumer: ModelsResponse
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

enhancement, documentation, tests

🚥 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 clearly and accurately summarizes the main change: adding a TypeScript SDK client for listing provider models, which is the core objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
sdks/typescript/tests/integration.test.ts (1)

130-135: ⚡ Quick win

Strengthen the models contract assertion to validate element shape.

Current checks only assert array-ness. Add item-level checks (when arrays are non-empty) for value, label, and optional boolean default to catch response normalization regressions.

Suggested enhancement
   describe("Models", () => {
     it("should list models for a provider", async () => {
       const models = await client.models.list("openai");

       expect(Array.isArray(models.language_models)).toBe(true);
       expect(Array.isArray(models.embedding_models)).toBe(true);
+
+      const firstLanguage = models.language_models[0];
+      if (firstLanguage) {
+        expect(typeof firstLanguage.value).toBe("string");
+        expect(typeof firstLanguage.label).toBe("string");
+        if ("default" in firstLanguage) {
+          expect(typeof firstLanguage.default).toBe("boolean");
+        }
+      }
+
+      const firstEmbedding = models.embedding_models[0];
+      if (firstEmbedding) {
+        expect(typeof firstEmbedding.value).toBe("string");
+        expect(typeof firstEmbedding.label).toBe("string");
+        if ("default" in firstEmbedding) {
+          expect(typeof firstEmbedding.default).toBe("boolean");
+        }
+      }
     });
   });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdks/typescript/tests/integration.test.ts` around lines 130 - 135, Update the
test case in the "it('should list models for a provider', ...)" block that calls
client.models.list("openai") to not only assert Array.isArray for
models.language_models and models.embedding_models but, when each array is
non-empty, iterate their items and assert each item has a string "value", a
string "label", and if "default" is present it is a boolean; use the existing
test identifiers (client.models.list, models.language_models,
models.embedding_models) to locate the test and add these element-shape
assertions to catch response normalization regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/typescript/src/models.ts`:
- Around line 16-18: The list method is currently interpolating the raw provider
into the request path, which can produce invalid URLs; in async list(provider:
string): Promise<ModelsResponse> validate/normalize provider (e.g., trim and
ensure non-empty) and use encodeURIComponent(provider) when building the path
passed to this.client._request (replace `/api/v1/models/${provider}` with
`/api/v1/models/${encodeURIComponent(provider)}`), and throw or return an error
for invalid input to avoid sending malformed requests.

---

Nitpick comments:
In `@sdks/typescript/tests/integration.test.ts`:
- Around line 130-135: Update the test case in the "it('should list models for a
provider', ...)" block that calls client.models.list("openai") to not only
assert Array.isArray for models.language_models and models.embedding_models but,
when each array is non-empty, iterate their items and assert each item has a
string "value", a string "label", and if "default" is present it is a boolean;
use the existing test identifiers (client.models.list, models.language_models,
models.embedding_models) to locate the test and add these element-shape
assertions to catch response normalization regressions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 53124c11-e450-47f6-9b31-8abd51574131

📥 Commits

Reviewing files that changed from the base of the PR and between 62760c4 and 84217aa.

📒 Files selected for processing (6)
  • sdks/typescript/README.md
  • sdks/typescript/src/client.ts
  • sdks/typescript/src/index.ts
  • sdks/typescript/src/models.ts
  • sdks/typescript/src/types.ts
  • sdks/typescript/tests/integration.test.ts

Comment on lines +16 to +18
async list(provider: string): Promise<ModelsResponse> {
const response = await this.client._request("GET", `/api/v1/models/${provider}`);
const data = await response.json();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Encode and validate provider before building the request path.

Direct interpolation in Line 17 can produce invalid or unintended paths when provider contains /, spaces, or reserved characters. Add a basic guard and encodeURIComponent(provider) before calling _request.

Suggested fix
   async list(provider: string): Promise<ModelsResponse> {
-    const response = await this.client._request("GET", `/api/v1/models/${provider}`);
+    const normalizedProvider = provider.trim();
+    if (!normalizedProvider) {
+      throw new Error("provider is required");
+    }
+    const response = await this.client._request(
+      "GET",
+      `/api/v1/models/${encodeURIComponent(normalizedProvider)}`
+    );
     const data = await response.json();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async list(provider: string): Promise<ModelsResponse> {
const response = await this.client._request("GET", `/api/v1/models/${provider}`);
const data = await response.json();
async list(provider: string): Promise<ModelsResponse> {
const normalizedProvider = provider.trim();
if (!normalizedProvider) {
throw new Error("provider is required");
}
const response = await this.client._request(
"GET",
`/api/v1/models/${encodeURIComponent(normalizedProvider)}`
);
const data = await response.json();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdks/typescript/src/models.ts` around lines 16 - 18, The list method is
currently interpolating the raw provider into the request path, which can
produce invalid URLs; in async list(provider: string): Promise<ModelsResponse>
validate/normalize provider (e.g., trim and ensure non-empty) and use
encodeURIComponent(provider) when building the path passed to
this.client._request (replace `/api/v1/models/${provider}` with
`/api/v1/models/${encodeURIComponent(provider)}`), and throw or return an error
for invalid input to avoid sending malformed requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant