This prompt is designed for documentation engineers and API platform teams who need to generate realistic, valid, and annotated example payloads directly from an OpenAPI specification. The core job-to-be-done is to eliminate the manual, error-prone work of crafting cURL commands, multi-language request snippets, and sample response bodies that accurately reflect the live API contract. The ideal user is someone integrating this prompt into a CI/CD documentation pipeline, where every schema change triggers a regeneration of examples to prevent drift between the docs and the API's actual behavior.
Prompt
Example Request and Response Generation Prompt Template

When to Use This Prompt
Define the job, ideal user, and constraints for generating example API requests and responses from an OpenAPI schema.
Use this prompt when you have a stable, machine-readable OpenAPI schema and need to produce developer-facing examples at scale. It is particularly effective for REST APIs with well-defined JSON request and response bodies. You should not use this prompt for generating examples from raw code without a spec, for real-time API exploration where a live client is more appropriate, or for APIs that rely heavily on non-JSON payloads like multipart form data or binary streams without explicit schema definitions. The prompt assumes the input schema is the source of truth; it will not question or correct the schema itself.
Before using this prompt, ensure your OpenAPI schema is complete, including examples or example fields where possible, as the model will prioritize these for grounding. The prompt's value is in its ability to generate multiple language variants and annotate the meaning of each field, but it requires a strict evaluation harness to validate that the generated JSON complies with the referenced schema. Do not rely on this prompt for endpoints with complex, stateful business logic where a realistic example depends on a specific sequence of prior API calls; in those cases, supplement the output with a manual 'Setup' note. The next step is to copy the prompt template and wire it into a documentation generation harness that validates output before publication.
Use Case Fit
Where this prompt works and where it does not. Use these cards to decide if the Example Request and Response Generation Prompt Template is the right tool for your documentation pipeline.
Good Fit: Schema-First API Docs
Use when: you have a complete, validated OpenAPI 3.x spec with defined schemas, examples, and error responses. The prompt excels at translating structured spec objects into realistic, multi-language request/response examples. Guardrail: validate the spec with an OpenAPI linter before feeding it to the prompt to prevent garbage-in, garbage-out example generation.
Bad Fit: Undocumented or Evolving APIs
Avoid when: the API lacks a formal spec, the spec is stale, or endpoints are in active development without finalized schemas. The prompt will hallucinate plausible but incorrect payloads. Guardrail: pair this prompt with the API Contract Drift Detection prompt first to confirm spec accuracy before generating examples.
Required Inputs
What you need: a valid OpenAPI spec (JSON or YAML), the target endpoint path and method, and a list of desired output languages (e.g., cURL, Python, JavaScript). Optional: authentication context and environment base URL. Guardrail: provide explicit [LANGUAGES] and [AUTH_CONTEXT] placeholders; missing auth context produces examples that fail on copy-paste.
Operational Risk: Stale Examples in Production
What to watch: generated examples drift from the live API as endpoints evolve. Users copy-paste broken cURL commands and file support tickets. Guardrail: run this prompt in CI/CD on every spec change, regenerate examples automatically, and add a last-validated timestamp to every example block in the published docs.
Operational Risk: Unrealistic Data Values
What to watch: the model generates placeholder values like "string", 0, or "example@email.com" that don't reflect real-world data shapes, leading to integration bugs. Guardrail: add a [DATA_CONSTRAINTS] section to the prompt specifying realistic value ranges, formats, and domain-appropriate examples (e.g., valid UUIDs, ISO dates, real enum members).
Variant: Multi-Language SDK Examples
What to watch: a single cURL example isn't enough for SDK-driven developer portals. Guardrail: extend the prompt with a [SDK_LANGUAGES] list and request language-idiomatic error handling, not just happy-path requests. Validate each generated snippet with a syntax checker and, ideally, a lightweight runtime test harness.
Copy-Ready Prompt Template
A reusable prompt template for generating realistic, schema-compliant example requests and responses from an OpenAPI specification.
This prompt template is designed to be dropped directly into your documentation pipeline. It takes an OpenAPI operation definition and a target language as input, and it produces a complete, annotated example that includes a cURL command, a request body, and a response body. The template uses square-bracket placeholders for all dynamic inputs, making it easy to parameterize in code. Before using this prompt in production, ensure you have a reliable method for extracting the relevant operation object from your OpenAPI spec and for selecting the target language.
codeYou are a senior developer documentation engineer. Your task is to generate a realistic, valid, and well-annotated example for a single API endpoint. You will be given an OpenAPI operation object and a target programming language. Generate an example that is suitable for inclusion in an API reference page. ### INPUTS - **Operation Object:** [OPENAPI_OPERATION_OBJECT] - **Target Language:** [TARGET_LANGUAGE] (e.g., 'curl', 'python', 'javascript') - **Base URL:** [BASE_URL] ### CONSTRAINTS - All generated data values must be realistic but clearly synthetic (e.g., use 'acme-corp' instead of 'example-org', 'sk_live_4f8s...' for API keys). - The request body must strictly validate against the `requestBody` schema in the operation object. - The response body must strictly validate against the success response schema (typically HTTP 200 or 201) in the operation object. - Include all required headers, especially `Authorization` and `Content-Type`. - For the cURL example, use a single-line command with minimal flags for readability. - For multi-language examples, wrap the code in a fenced code block with the correct language identifier. ### OUTPUT SCHEMA You must respond with a single JSON object conforming to this structure: { "endpoint_summary": "A one-line description of what the example demonstrates.", "curl_example": "A complete, copy-pasteable cURL command.", "request_example": { "description": "A brief explanation of the request body fields.", "code": "The request body in the target language, or as a JSON string if the language is curl." }, "response_example": { "description": "A brief explanation of the response body fields and status code.", "code": "The response body as a formatted JSON string." }, "notes": ["An array of strings with any important usage notes, such as idempotency key requirements or rate limit headers."] } ### RISK LEVEL: [RISK_LEVEL] - If RISK_LEVEL is 'high', add a prominent warning in the notes array that the example should not be used with production credentials. - If RISK_LEVEL is 'low', you may omit the warning.
To adapt this template, replace the placeholders with data from your source of truth. The [OPENAPI_OPERATION_OBJECT] should be the JSON object for a single path and method (e.g., paths./users.post). The [TARGET_LANGUAGE] drives the format of the request example. The [RISK_LEVEL] flag allows you to conditionally inject safety warnings for destructive operations like DELETE or payment endpoints. After generating the output, always run a programmatic validation step to confirm the generated JSON matches the OUTPUT_SCHEMA and that the request and response bodies validate against their respective schemas. This prevents malformed examples from reaching your documentation site.
Prompt Variables
Required inputs for the Example Request and Response Generation Prompt Template. Each placeholder must be supplied before the prompt is sent to the model. Missing or invalid inputs are the most common cause of schema-noncompliant or unrealistic generated examples.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[OPENAPI_SPEC] | Complete OpenAPI 3.x specification as JSON or YAML string containing the target endpoint's path item, operation object, and all referenced component schemas | openapi: 3.0.3 paths: /users: post: requestBody: content: application/json: schema: $ref: '#/components/schemas/CreateUserRequest' | Parse as valid OpenAPI 3.x document. Reject if missing paths, operationId, or requestBody for target endpoint. Reject if $ref targets are unresolvable within the provided spec fragment. |
[TARGET_OPERATION_ID] | OperationId of the endpoint for which examples are generated. Must match exactly one operation in the provided spec | createUser | Must be a non-empty string present in the provided [OPENAPI_SPEC] as an operationId. If operationId is missing from spec, use [TARGET_PATH] and [TARGET_METHOD] instead. |
[TARGET_PATH] | Path template of the endpoint, used as fallback when operationId is not available | /users | Must match a path item in [OPENAPI_SPEC]. Required only when [TARGET_OPERATION_ID] is null. Validate path exists in spec. |
[TARGET_METHOD] | HTTP method of the endpoint, used as fallback when operationId is not available | post | Must be one of: get, post, put, patch, delete, options, head. Required only when [TARGET_OPERATION_ID] is null. Validate method exists on the target path in spec. |
[EXAMPLE_COUNT] | Number of distinct example request/response pairs to generate per status code | 3 | Must be an integer between 1 and 10. Higher values increase token cost and may produce repetitive examples. Default to 3 if not specified. |
[TARGET_LANGUAGES] | List of programming languages for which to generate client code examples alongside raw HTTP | ["curl", "python", "javascript"] | Must be a non-empty array of strings from supported language set: curl, python, javascript, java, go, ruby, csharp, php. Reject unrecognized language values. curl is always included as the canonical HTTP example. |
[INCLUDE_ERROR_EXAMPLES] | Whether to generate example error responses for 4xx and 5xx status codes defined in the spec | Must be boolean true or false. When true, generate examples for all documented error responses. When false, generate only success response examples. Default to true for completeness. | |
[REALISTIC_DATA_SOURCE] | Optional reference to a data dictionary or seed data file that provides realistic values for fields instead of placeholder strings | null or base64-encoded JSON mapping field paths to sample values | If provided, parse as valid JSON object with field-path keys and sample-value values. If null, model generates synthetic but realistic values. Validate that referenced field paths exist in the request schema. |
Implementation Harness Notes
How to wire the example generation prompt into a reliable documentation pipeline with validation, retries, and schema compliance checks.
The Example Request and Response Generation prompt is designed to be embedded in a documentation generation pipeline, not used as a one-off chat interaction. The typical integration point is after an OpenAPI spec has been parsed and validated, but before the generated examples are published to a developer portal. The harness should accept a resolved OpenAPI schema object (with all $ref pointers dereferenced), an endpoint path, and an HTTP method as inputs. It then constructs the prompt, calls the model, and validates the output before the examples ever reach a docs page.
The implementation must include a schema compliance validator that checks every generated request and response body against the corresponding OpenAPI schema using a JSON Schema validator like ajv. If validation fails, the harness should retry with the validation errors appended to the prompt as [CONSTRAINTS] feedback, up to a configurable retry limit (typically 3 attempts). For multi-language code examples, the harness should also run a syntax check using the target language's parser or linter (e.g., curl --dry-run for cURL examples, python -m py_compile for Python snippets). Log every generation attempt, validation result, and retry count to an observability system so the team can track schema drift or model degradation over time.
For production use, prefer structured output mode (JSON mode or function calling with a defined schema) rather than relying on the model to format code blocks correctly. Define an output schema that includes fields for curl_example, request_body, response_body, response_status, and an array of language_examples with language and code properties. This makes parsing deterministic and allows the harness to extract individual components for different parts of the documentation page. If the endpoint requires authentication, the harness should inject realistic but clearly fake API keys or tokens (e.g., sk-... placeholders) and never use real credentials. For high-risk or regulated APIs, add a human review step before publication, flagging any examples where the model generated potentially confusing or unsafe parameter values.
Expected Output Contract
Fields, types, and validation rules for the example request and response payloads generated by this prompt. Use this contract to build a post-generation validator that rejects malformed or incomplete outputs before they reach documentation.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
[HTTP_METHOD] | string (GET, POST, PUT, PATCH, DELETE) | Must match one of the allowed HTTP methods defined in the source OpenAPI spec for the target endpoint. | |
[REQUEST_URL] | string (valid URL) | Must be a syntactically valid URL with correct base path, path parameters substituted, and query parameters URL-encoded. | |
[REQUEST_HEADERS] | object (key-value pairs) | Must include Content-Type and Authorization headers when required by the endpoint; header names must match the spec's parameter definitions. | |
[REQUEST_BODY] | object or null | If present, must validate against the requestBody JSON Schema from the OpenAPI spec; all required fields must be populated with realistic, non-placeholder values. | |
[RESPONSE_STATUS_CODE] | integer (100-599) | Must be a valid HTTP status code; must match one of the documented response codes for the endpoint in the spec. | |
[RESPONSE_HEADERS] | object (key-value pairs) | If present, must include Content-Type; rate-limit headers (X-RateLimit-*) must be present when the endpoint is rate-limited per the spec. | |
[RESPONSE_BODY] | object or null | If present, must validate against the response schema for the given status code in the OpenAPI spec; all required fields must be present and correctly typed. | |
[CURL_COMMAND] | string (valid shell command) | Must be a syntactically valid cURL command; must include the correct method flag, URL, headers, and body; must be copy-paste executable without modification. |
Common Failure Modes
What breaks first when generating example requests and responses from OpenAPI schemas, and how to guard against it.
Schema Drift Between Spec and Reality
What to watch: The OpenAPI spec is stale. The model generates examples that match the spec but fail against the live API because a field was added, a type changed, or an enum value was deprecated. Guardrail: Run a pre-generation contract test comparing the spec against a live API snapshot. Flag any endpoint where the spec and reality diverge before generating examples.
Unrealistic or Placeholder Data Values
What to watch: The model fills string fields with 'string', emails with 'user@example.com', and IDs with '123'. These examples don't help integrators understand real data shape or constraints. Guardrail: Provide a data dictionary or seed values for critical fields. Add a post-generation validator that flags any value matching common placeholder patterns and requests regeneration with realistic constraints.
Missing Required Fields in Nested Objects
What to watch: The model generates a valid top-level request body but omits a required field inside a deeply nested allOf or oneOf schema. The example looks plausible but fails validation. Guardrail: Run every generated example through a strict OpenAPI schema validator before publishing. Reject any example that doesn't pass additionalProperties: false and required field checks at every nesting level.
Enum and Constraint Violations
What to watch: The model invents an enum value that isn't in the spec, exceeds a maxLength, or violates a pattern regex. These are the most common silent failures in generated examples. Guardrail: Extract all enum, pattern, minimum, maximum, minLength, and maxLength constraints from the schema. Add them as explicit rules in the prompt and validate each generated field against its constraints.
Multi-Language Example Inconsistency
What to watch: The cURL example, Python snippet, and JavaScript example all use different parameter values or request bodies. Integrators lose trust when examples don't match across languages. Guardrail: Generate the canonical request body first, then derive all language-specific examples from that single source. Validate that all variants produce the same logical request when parsed.
Authentication Context Omission
What to watch: The generated cURL command or code snippet omits the Authorization header, uses a placeholder token that looks real, or doesn't match the security scheme defined in the spec. Guardrail: Extract the security scheme from the OpenAPI spec and inject the correct auth pattern into every example. Use a clearly fake token format like $API_KEY or Bearer <your-token-here> that cannot be mistaken for a real credential.
Evaluation Rubric
Criteria for evaluating generated example requests and responses before they are published in API reference documentation. Use this rubric to gate outputs against schema compliance, realism, and documentation standards.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Schema Compliance | Request and response bodies validate against the provided OpenAPI schema with zero errors | Validation errors, missing required fields, or incorrect types in the generated payload | Run JSON Schema validator against the generated output using the source spec |
Realistic Data Values | All example values are plausible and non-generic; no 'string', 'foo', or 'test' placeholders | Placeholder strings, unrealistic IDs, or data that contradicts the field description | Spot-check 5 random fields for semantic match with their description and type |
cURL Command Validity | Generated cURL command executes successfully against a mock server or returns the expected error | Malformed URL, missing required headers, or incorrect HTTP method | Execute cURL in a sandboxed test environment with a mock endpoint |
Multi-Language Consistency | All language examples (Python, JavaScript, etc.) produce equivalent HTTP requests with identical payloads | Missing parameters, different data values, or inconsistent auth handling across languages | Diff the serialized request bodies and headers across all generated language examples |
Error Response Coverage | At least one error response example is included per endpoint when error codes are defined in the spec | Only happy-path responses generated for endpoints that define 4xx or 5xx responses | Count error response examples against the spec's defined error codes |
Auth Header Presence | All example requests include the correct authorization header or token placeholder as defined in the security scheme | Missing Authorization header, wrong auth type, or hardcoded real credentials | Regex match for auth header pattern and verify no live tokens are present |
Annotation Fidelity | Generated examples match any example or example-payload annotations present in the source spec | Generated output contradicts or ignores explicit examples defined in the OpenAPI spec | String distance comparison between spec-provided examples and generated output |
Readability for Developers | Output is formatted with consistent indentation, line breaks, and comments explaining non-obvious values | Minified JSON, missing comments, or inconsistent formatting across examples | Manual review against a style checklist or automated linting for JSON/XML formatting |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Use the base prompt with a single OpenAPI operation and lighter validation. Drop the multi-language requirement and focus on one output format (cURL + JSON response only). Remove the realistic-data constraint and accept placeholder values like "string" or 0.
codeGenerate one example request and response for [OPERATION_ID] from [OPENAPI_SPEC]. Output: cURL command and JSON response body only.
Watch for
- Schema violations that would fail a real API call
- Missing required fields in the response example
- Placeholder values that confuse downstream reviewers

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us