Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
There was a problem hiding this comment.
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 Replicationwith 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.jsonnavigation 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() |
There was a problem hiding this comment.
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.
| prompt_data = requests.get(url, headers=headers).json() | |
| response = requests.get(url, headers=headers, timeout=10) | |
| response.raise_for_status() | |
| prompt_data = response.json() |
| const { data } = await listRes.json(); | ||
| const promptId = data[0].id; | ||
|
|
||
| const promptData = await fetch(`${BASE}/prompts/${promptId}`, { headers }).then((r) => | ||
| r.json() | ||
| ); |
There was a problem hiding this comment.
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.
| 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(); |
| const { data } = await listRes.json(); | ||
| const promptId = data[0].id; | ||
|
|
||
| const promptData = await fetch(`${BASE}/prompts/${promptId}`, { headers }).then((r) => | ||
| r.json() | ||
| ); |
There was a problem hiding this comment.
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().
| 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(); |
| const { data } = await listRes.json(); | ||
| const promptData = await fetch(`${BASE}/prompts/${data[0].id}`, { headers }).then((r) => | ||
| r.json() | ||
| ); | ||
|
|
There was a problem hiding this comment.
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.
| 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(); |
| const created = await fetch(`${BASE}/prompts`, { | ||
| method: 'POST', | ||
| headers: { ...headers, 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify(payload), | ||
| }).then((r) => r.json()); |
There was a problem hiding this comment.
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.
| 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)}` | |
| ); | |
| } |
| 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() |
There was a problem hiding this comment.
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.
| 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() |
| const data = await fetch(`${BASE}/prompts/${promptId}`, { headers }).then((r) => | ||
| r.json() | ||
| ); |
There was a problem hiding this comment.
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.
| 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(); |
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
guides/use-cases/automated-prompt-replication.mdxcollection_id, and rate limits.docs.json— page listed under Use Cases in both mirrored Cookbooks trees (placed after How to use OpenAI SDK with Portkey Prompt Templates).guides/use-cases.mdxproduct/prompt-engineering-studio/prompt-guides.mdx→/guides/use-cases/automated-prompt-replication/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