Skip to content

Add inference-engine snippets command to generate curl, Python, and JS client code #28

@AK11105

Description

@AK11105

What problem does this solve?

After deploying a model, users have to manually write client code to call it. The request shape (model, version, data) and the correct sample_input type are already known from the deploy flow — there is no reason the user should have to reconstruct them.

Proposed solution

New command: inference-engine snippets sentiment:v1 [--output dir] [--host url]

Reads sample_input, name, and version from deployment.json. Fails with a clear message if deployment.json is absent. --host defaults to http://localhost:8000.

Prints (or writes to --output) ready-to-use client code in three languages:

curl

curl -X POST http://localhost:8000/predict \
  -H "X-API-Key: <your-key>" \
  -H "Content-Type: application/json" \
  -d '{"model": "sentiment", "version": "v1", "data": "great movie"}'

Python (httpx)

import httpx
response = httpx.post(
    "http://localhost:8000/predict",
    headers={"X-API-Key": "<your-key>"},
    json={"model": "sentiment", "version": "v1", "data": "great movie"},
)
print(response.json())

JavaScript (fetch)

const response = await fetch("http://localhost:8000/predict", {
  method: "POST",
  headers: {"X-API-Key": "<your-key>", "Content-Type": "application/json"},
  body: JSON.stringify({model: "sentiment", version: "v1", data: "great movie"}),
});
console.log(await response.json());

Static templates with variable substitution. No LLM needed. Implementation is ~60 lines.

Alternatives considered

Relying on the Swagger UI at /docs. Swagger shows the schema but doesn't pre-fill sample_input or generate copy-pasteable multi-language snippets.

Area

CLI (deploy / fix)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions