Last reviewed: 2026-07-21
Direct answer
Use rendered text when the reader only needs to see the answer a tutorial produced. Use raw JSON when the tutorial is teaching response parsing, field mapping, logging, error handling, storage, or endpoint comparison. Use both when the reader must connect the visible answer to the documented response shape.
For a CometAPI text tutorial, the safest pattern is usually: show the rendered answer first, then show the smallest raw JSON excerpt that explains where that answer came from. That keeps the page readable for a developer who is trying to finish an integration, while still giving maintainers enough evidence to check the example against the current CometAPI documentation.
This choice matters because Chat Completions and Responses examples are not just screenshots of text. They are contracts between the request, the response object, the parser, and the page explanation. The CometAPI Chat Completions reference documents a chat completion endpoint and shows a response shape with a choices array and assistant message content. The Responses reference is a separate text endpoint family. A tutorial should not blur those families by rendering text from one endpoint while explaining fields from the other.
For endpoint choice before presentation choice, see Choose between CometAPI Chat Completions and Responses . For field-level storage decisions after you choose an output format, see Choose Reliable Storage Fields for CometAPI Text Results .
Output selection workflow
Setup assumptions: you have a CometAPI API key stored outside the tutorial, an endpoint family selected from the current docs, a model identifier copied from a live account or current model page, and a local fixture that does not contain secrets. Published snippets should use <API_KEY_PLACEHOLDER> anywhere a credential would otherwise appear.
Happy-path request plan: send one minimal text request using the endpoint family documented for the tutorial. Save the full local response outside the article workspace, then decide what the reader actually needs. If the tutorial teaches a quick integration outcome, render the text value and mention that the full object should be inspected locally. If the tutorial teaches parsing, include a short JSON excerpt beside the rendered text. If the tutorial teaches endpoint differences, keep the excerpts separated by endpoint family so readers do not copy fields into the wrong client.
Error-path check: run one intentionally incomplete local fixture, such as omitting a required request input, and confirm that the tutorial treats the result as a failed request. Do not render an error message as if it were successful output. Do not copy account-specific request identifiers, private metadata, or full provider responses into the published guide.
Minimum assertions: record the endpoint family, whether the request reached a success or failure category, whether a displayable text value was present on the happy path, whether the raw excerpt matches the fields explained in the prose, and whether the failure path was handled without inventing retry, pricing, quota, or uptime behavior.
Pass/fail logging fields:
run_id: "tutorial-output-smoke-<YYYYMMDD>"
endpoint_family: "<chat_or_responses>"
request_fixture: "<fixture_name>"
rendered_text_present: "<true_or_false>"
raw_json_excerpt_saved: "<true_or_false>"
raw_json_excerpt_used_in_article: "<true_or_false>"
error_path_result: "<handled_or_not_handled>"
article_output_choice: "<rendered_text_raw_json_or_both>"
notes: "<short_placeholder_note>"
Do not assert exact pricing, quota, latency, uptime, provider availability, or a specific model response unless those details are verified in a current public source at the time of the test.
Who this is for
This guide is for tutorial authors, developer educators, and maintainers who write CometAPI examples for text generation. It is most useful when a page has to decide between a clean user-facing answer and a lower-level response object.
Use it when you are preparing a CometAPI raw JSON rendered text tutorial, updating a Chat Completions walkthrough, comparing the Responses endpoint with Chat Completions, or deciding what to store from a text result. It also helps when a tutorial has grown too noisy because every example includes a full response body even though the reader only needs one output string.
It is not a substitute for the CometAPI docs. Treat it as a presentation rule for tutorial pages. The endpoint path, request body, response fields, model availability, cost notes, and support instructions still need to come from the current public documentation.
Key takeaways
- Rendered text is best when the tutorial goal is comprehension: the reader asks a question, receives text, and only needs to confirm the visible result.
- Raw JSON is best when the tutorial goal is implementation: the reader must inspect fields, write a parser, choose storage columns, handle errors, or compare endpoint families.
- Showing both is safest when the tutorial explains provenance: the rendered paragraph should map to a small documented response excerpt.
- Keep raw excerpts short. A useful excerpt is better than a full response dump that includes fields the article never explains.
- Use
<API_KEY_PLACEHOLDER>in examples and keep real credentials outside the page. - Recheck the current Chat Completions and Responses references before naming endpoint-specific fields.
- Use pricing and support pages only for boundary wording, such as checking current costs before larger runs or escalating unresolved account issues with sanitized metadata.
Sources checked
- CometAPI documentation - accessed 2026-07-21; purpose: verify current CometAPI documentation navigation.
- CometAPI chat completions reference - accessed 2026-07-21; purpose: verify chat completion contract areas.
- CometAPI responses reference - accessed 2026-07-21; purpose: verify responses endpoint contract areas.
- CometAPI pricing documentation - accessed 2026-07-21; purpose: verify pricing documentation boundaries.
- CometAPI help center - accessed 2026-07-21; purpose: verify support and escalation documentation areas.
Contract details to verify
| Area | What to verify | Source URL | Accessed | Safe candidate wording |
|---|---|---|---|---|
| Endpoint family | Whether the tutorial uses Chat Completions or Responses for the example | https://apidoc.cometapi.com/api/text/chat and https://apidoc.cometapi.com/api/text/responses | 2026-07-21 | “Use the endpoint family shown in the current CometAPI reference for this example.” |
| Rendered text | Which documented response location contains displayable text | https://apidoc.cometapi.com/api/text/chat and https://apidoc.cometapi.com/api/text/responses | 2026-07-21 | “Render only the text value your fixture returned from the documented response area.” |
| Raw JSON excerpt | Which fields are relevant to the parser, logger, or storage example | https://apidoc.cometapi.com/api/text/chat and https://apidoc.cometapi.com/api/text/responses | 2026-07-21 | “Keep the JSON excerpt limited to the fields the tutorial explains.” |
| Setup context | Whether the example uses documented CometAPI setup patterns and externalized key handling | https://apidoc.cometapi.com/ | 2026-07-21 | “Store credentials outside the snippet and use placeholders in published examples.” |
| Cost notes | Whether the tutorial needs a cost caveat instead of a fixed price claim | https://apidoc.cometapi.com/pricing/about-pricing | 2026-07-21 | “Check current pricing before running larger examples.” |
| Support notes | Whether unresolved failures should be escalated through documented support paths | https://apidoc.cometapi.com/support/help-center | 2026-07-21 | “Escalate unexplained account or service issues with sanitized request metadata.” |
Failure modes
- Full-response dumping: the tutorial pastes a large JSON object but explains only one text field. This makes the article harder to scan and increases the chance that unrelated fields go stale.
- Render-only ambiguity: the tutorial prints the answer but never shows where it came from. That is acceptable for a quick demo, but weak for a parser, storage, or debugging guide.
- Endpoint mixing: the prose names one endpoint family while the sample shape belongs to another. Keep Chat Completions and Responses examples visibly separated unless the article is explicitly comparing them.
- Credential leakage: a local request, screenshot, or log includes a real key or account-specific metadata. Replace credentials with
<API_KEY_PLACEHOLDER>and remove private request details before publication. - Unsupported exactness: the article claims a fixed model answer, price, limit, latency, or uptime value without a current public source. Keep these as verification steps, not promises.
- Overfitted assertions: a test fails because the text wording changed even though the documented response shape is valid. Assert the presence of displayable text and the expected object family, not a sentence that may vary.
Reader next step
Before publishing or updating a CometAPI tutorial, make one output-format decision and write it at the top of your draft notes: rendered text only, raw JSON only, or both. Then run the small happy-path and error-path checks above, compare the fields you plan to mention against the current Chat Completions or Responses page, and remove any JSON fields that the article does not explain.
If your tutorial needs a reusable parsing pattern, continue with Read CometAPI Text Responses Without Guessing the Shape . If it mainly needs request-side checks before output review, use Review CometAPI Request Bodies Before Tutorial Tests next.
Use Add a Laravel Route for a CometAPI Chat Demo as the next comparison point. Keep Print CometAPI Chat Completion JSON Fields from a CLI nearby for setup and permission checks.
FAQ
Should every tutorial include raw JSON?
No. Include raw JSON when the reader must inspect fields, write a parser, compare endpoint shapes, store response data, or troubleshoot failures. For a simple usage walkthrough, rendered text plus a clean link to the relevant reference is often enough.
How much JSON should be shown?
Show the smallest excerpt that supports the lesson. If the tutorial explains one text value and one finish or status field, do not paste unrelated usage, metadata, or provider-specific fields unless the source-backed lesson needs them.
Can I use a real API key in the snippet?
No. Use <API_KEY_PLACEHOLDER> in examples and keep real keys in local environment variables or a secure secret store. Do not paste keys, account identifiers, or private request metadata into article text.
Should a tutorial assert an exact model answer?
Usually not. A smoke test should assert that a valid response shape was returned and that displayable text is present. Exact wording can vary and should not be treated as a stable contract unless the test fixture and source explicitly require it.
When should I show both rendered text and raw JSON?
Show both when the page teaches readers how the visible answer maps back to the API response. Put the rendered answer first, then a short JSON excerpt that proves where it came from and matches the fields explained in the article.
What should I do when the docs and my local response differ?
Pause the article change until you can explain the difference with current public docs, a sanitized local fixture, or a support response that can be summarized without private details. Do not publish a field-level claim that only exists in an unexplained local response.