Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

2.3 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { modelUsageExample } from "./modelUsageExample";

const BASE_URL = "https://proxy.example.com";

describe("modelUsageExample", () => {
  it("posts a decision model to /v1/systemone on the proxy", () => {
    const example = modelUsageExample("evaluation", BASE_URL, "jev-latest", "Authorization");
    expect(example).toContain('"https://proxy.example.com/v1/systemone"');
    expect(example).toContain('"model": "jev-latest"');
    expect(example).toContain('"type": "noul"');
    expect(example).not.toContain("chat.completions");
  });

  it("sends the key in the header the proxy reads keys from", () => {
    expect(modelUsageExample("evaluation", BASE_URL, "jev-latest", "Authorization")).toContain(
      'headers={"Authorization": "Bearer your_api_key"}',
    );
    expect(modelUsageExample("evaluation", BASE_URL, "jev-latest", "X-Litellm-Key")).toContain(
      'headers={"X-Litellm-Key": "Bearer your_api_key"}',
    );
  });

  it("posts an extraction model to /v1/extraction with typed fields", () => {
    const example = modelUsageExample("extraction", BASE_URL, "clairic", "X-Litellm-Key");
    expect(example).toContain('"https://proxy.example.com/v1/extraction"');
    expect(example).toContain('headers={"X-Litellm-Key": "Bearer your_api_key"}');
    expect(example).toContain('"model": "clairic"');
    expect(example).toContain('"fields": {');
    expect(example).not.toContain("chat.completions");
    expect(example).not.toContain("/v1/systemone");
  });

  it("keeps the chat completions example for every other mode", () => {
    for (const mode of ["chat", null, undefined]) {
      const example = modelUsageExample(mode, BASE_URL, "gpt-5.5", "Authorization");
      expect(example).toContain("client.chat.completions.create(");
      expect(example).toContain('base_url="https://proxy.example.com"');
      expect(example).toContain('model="gpt-5.5"');
      expect(example).not.toContain("/v1/systemone");
      expect(example).not.toContain("/v1/extraction");
    }
  });

  it("escapes quotes in a model name so the snippet stays valid Python", () => {
    expect(modelUsageExample("evaluation", BASE_URL, 'team"model', "Authorization")).toContain(
      '"model": "team\\"model"',
    );
    expect(modelUsageExample("chat", BASE_URL, 'team"model', "Authorization")).toContain('model="team\\"model"');
  });
});