Skip to content

Guide prompt api#851

Open
harshitkumar454 wants to merge 2 commits intomainfrom
guide-prompt-api
Open

Guide prompt api#851
harshitkumar454 wants to merge 2 commits intomainfrom
guide-prompt-api

Conversation

@harshitkumar454
Copy link
Copy Markdown

docs: add Automated Prompt Replication use-case (Admin API)

Summary

Adds a Cookbook that walks through bulk-replicating Portkey prompts and retargeting them to a new model using the Admin API (GET /v1/prompts, GET /v1/prompts/{id}, POST /v1/prompts). The page is registered under Cookbooks → Use Cases and includes Python and Node.js examples.

What’s included

  • New page: guides/use-cases/automated-prompt-replication.mdx
    • Scenario, auth (Admin vs workspace key), step-by-step flow, full scripts in Python and Node.js (tabs), notes on response field names, collection_id, and rate limits.
    • Links to List / Retrieve / Create prompt reference and to the Prompt API for runtime completions.
  • Navigation: docs.json — page listed under Use Cases in both mirrored Cookbooks trees (placed after How to use OpenAI SDK with Portkey Prompt Templates).
  • Discovery:
    • Card on guides/use-cases.mdx
    • Card on product/prompt-engineering-studio/prompt-guides.mdx/guides/use-cases/automated-prompt-replication
  • Redirects (for old or intermediate URLs):
    • /api-reference/admin-api/control-plane/prompts/automated-prompt-replication/guides/use-cases/automated-prompt-replication
    • /guides/prompts/automated-prompt-replication/guides/use-cases/automated-prompt-replication

@mintlify
Copy link
Copy Markdown
Contributor

mintlify bot commented Apr 8, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
portkey-docs 🟢 Ready View Preview Apr 8, 2026, 12:20 PM

Copy link
Copy Markdown

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

Adds a new Cookbook use-case guide describing how to bulk-replicate Portkey Prompts via the Admin API, and wires it into site navigation/discovery (cards + docs nav) with redirects for legacy URLs.

Changes:

  • Adds a new guide page: Automated Prompt Replication with Python + Node.js scripts using List/Retrieve/Create prompt endpoints.
  • Adds discovery cards linking to the new use-case from the Use Cases overview and Prompt Engineering Studio guides.
  • Registers the page in docs.json navigation and adds redirects from older URL paths.

Reviewed changes

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

File Description
product/prompt-engineering-studio/prompt-guides.mdx Adds a card linking to the new automated prompt replication guide.
guides/use-cases/automated-prompt-replication.mdx New cookbook page with step-by-step workflow and full Python/Node.js examples.
guides/use-cases.mdx Adds a Use Cases card linking to the new guide.
docs.json Adds the page to both Cookbooks → Use Cases nav trees and introduces redirects to the new URL.

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

prompt_id = prompt_ids[0]
url = f"{BASE}/prompts/{prompt_id}"

prompt_data = requests.get(url, headers=headers).json()
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

In the Python Step 2 snippet, the GET response is parsed with .json() without checking for HTTP errors first. If the request fails (401/404/etc.), users may get a confusing JSON parse / KeyError later. Consider calling raise_for_status() (and optionally using a short timeout) before reading .json() to make failures explicit.

Suggested change
prompt_data = requests.get(url, headers=headers).json()
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()
prompt_data = response.json()

Copilot uses AI. Check for mistakes.
Comment on lines +90 to +95
const { data } = await listRes.json();
const promptId = data[0].id;

const promptData = await fetch(`${BASE}/prompts/${promptId}`, { headers }).then((r) =>
r.json()
);
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

In the Node.js Step 2 snippet, listRes is not checked for ok before calling .json(). If auth is wrong or the API errors, the example may proceed with data[0] on an error payload. Add an ok check (and surface status/body) before parsing.

Suggested change
const { data } = await listRes.json();
const promptId = data[0].id;
const promptData = await fetch(`${BASE}/prompts/${promptId}`, { headers }).then((r) =>
r.json()
);
if (!listRes.ok) {
const body = await listRes.text();
throw new Error(`List prompts failed: ${listRes.status} ${body}`);
}
const { data } = await listRes.json();
const promptId = data[0].id;
const promptRes = await fetch(`${BASE}/prompts/${promptId}`, { headers });
if (!promptRes.ok) {
const body = await promptRes.text();
throw new Error(`Retrieve prompt failed: ${promptRes.status} ${body}`);
}
const promptData = await promptRes.json();

Copilot uses AI. Check for mistakes.
Comment on lines +90 to +95
const { data } = await listRes.json();
const promptId = data[0].id;

const promptData = await fetch(`${BASE}/prompts/${promptId}`, { headers }).then((r) =>
r.json()
);
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

In the Node.js Step 2 snippet, the retrieve call parses JSON without validating r.ok. If the prompt fetch fails, the example will still log an error payload as if it were a prompt. Consider checking ok and throwing a descriptive error before r.json().

Suggested change
const { data } = await listRes.json();
const promptId = data[0].id;
const promptData = await fetch(`${BASE}/prompts/${promptId}`, { headers }).then((r) =>
r.json()
);
if (!listRes.ok) throw new Error(`List prompts failed: ${listRes.status}`);
const { data } = await listRes.json();
const promptId = data[0].id;
const promptRes = await fetch(`${BASE}/prompts/${promptId}`, { headers });
if (!promptRes.ok) throw new Error(`Retrieve prompt failed: ${promptRes.status}`);
const promptData = await promptRes.json();

Copilot uses AI. Check for mistakes.
Comment on lines +141 to +145
const { data } = await listRes.json();
const promptData = await fetch(`${BASE}/prompts/${data[0].id}`, { headers }).then((r) =>
r.json()
);

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

In the Node.js Step 3 snippet, the list/retrieve calls (listRes, prompt fetch) are not checked for ok before reading .json(), which can lead to confusing failures when auth/pagination errors occur. Align this snippet with the Step 1 pattern by validating ok for each fetch before using the response body.

Suggested change
const { data } = await listRes.json();
const promptData = await fetch(`${BASE}/prompts/${data[0].id}`, { headers }).then((r) =>
r.json()
);
if (!listRes.ok) {
throw new Error(`List prompts failed: ${listRes.status} ${await listRes.text()}`);
}
const { data } = await listRes.json();
const promptRes = await fetch(`${BASE}/prompts/${data[0].id}`, { headers });
if (!promptRes.ok) {
throw new Error(`Retrieve prompt failed: ${promptRes.status} ${await promptRes.text()}`);
}
const promptData = await promptRes.json();

Copilot uses AI. Check for mistakes.
Comment on lines +158 to +162
const created = await fetch(`${BASE}/prompts`, {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
}).then((r) => r.json());
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

In the Node.js Step 3 snippet, the create request parses JSON without checking r.ok, so errors can be logged as if creation succeeded. Consider checking ok and including the response body in the thrown error before logging the created prompt.

Suggested change
const created = await fetch(`${BASE}/prompts`, {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
}).then((r) => r.json());
const createRes = await fetch(`${BASE}/prompts`, {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
const created = await createRes.json();
if (!createRes.ok) {
throw new Error(
`Failed to create prompt (${createRes.status}): ${JSON.stringify(created)}`
);
}

Copilot uses AI. Check for mistakes.
prompt_ids = [row["id"] for row in list_res.json()["data"]]

for prompt_id in prompt_ids:
data = requests.get(f"{BASE}/prompts/{prompt_id}", headers=headers).json()
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

In the full-loop Python example, each prompt retrieve uses .json() directly without raise_for_status(). If any prompt ID is invalid or permissions differ across collections, the loop may fail later with unclear errors. Consider calling raise_for_status() on the retrieve response before building the payload.

Suggested change
data = requests.get(f"{BASE}/prompts/{prompt_id}", headers=headers).json()
retrieve_res = requests.get(f"{BASE}/prompts/{prompt_id}", headers=headers)
retrieve_res.raise_for_status()
data = retrieve_res.json()

Copilot uses AI. Check for mistakes.
Comment on lines +223 to +225
const data = await fetch(`${BASE}/prompts/${promptId}`, { headers }).then((r) =>
r.json()
);
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

In the full-loop Node.js example, the per-prompt retrieve call parses JSON without checking r.ok. If any prompt fetch fails mid-loop, the code may attempt to create a replica from an error payload. Consider checking ok (and surfacing status/body) before using the retrieved data.

Suggested change
const data = await fetch(`${BASE}/prompts/${promptId}`, { headers }).then((r) =>
r.json()
);
const retrieveRes = await fetch(`${BASE}/prompts/${promptId}`, { headers });
if (!retrieveRes.ok) {
const body = await retrieveRes.text();
throw new Error(`Retrieve failed for ${promptId}: ${retrieveRes.status} ${body}`);
}
const data = await retrieveRes.json();

Copilot uses AI. Check for mistakes.
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.

2 participants