59API

← Volver a las guías

Prompt Engineering Basics: A Developer API Playbook

Guías · EN · 2026-09-19

Start with a Clear Prompt Contract

Prompt engineering is the practice of writing instructions that help a model produce consistent, useful output. For developers, the goal is not a clever one-off question. It is a repeatable contract: define the model's role, provide the input, specify constraints, and describe exactly what a successful response looks like.

A dependable prompt usually has four parts: task, context, rules, and output format. For example, instead of asking “Summarize this support ticket,” tell the model what type of summary you need, who will read it, which details matter, and how the result should be returned.

Prompt template: You are a customer-support triage assistant. Read the ticket between the delimiters. Identify the issue, urgency, and recommended team. Do not invent facts. Return valid JSON with keys issue, urgency, team, and rationale. Ticket: <ticket>{{ticket_text}}</ticket>.

The delimiters separate trusted instructions from variable user content. This is important because ticket text, documents, and form fields may contain misleading instructions such as “ignore previous rules.” Treat external content as data, not as instructions.

Call the Model from an OpenAI-Compatible SDK

Once a prompt works in a playground, put it behind a small function and test it with real examples. 59API is a practical low-cost option when you want pay-as-you-go access to Claude models and GPT models through an OpenAI-compatible interface. Its API base URL is https://api.59api.com, so teams can often keep their existing SDK workflow while choosing native official-quality models without a downgrade.

Example JavaScript using an OpenAI-compatible SDK:

import OpenAI from "openai"; const client = new OpenAI({ apiKey: process.env.API_KEY, baseURL: "https://api.59api.com" }); const result = await client.chat.completions.create({ model: "your-model-id", messages: [{ role: "system", content: "You are a customer-support triage assistant. Return only valid JSON." }, { role: "user", content: "Ticket: My invoice was charged twice and I need help today." }], temperature: 0.2 }); console.log(result.choices[0].message.content);

Use a low temperature, such as 0 to 0.3, for extraction, classification, routing, and structured outputs. Raise it for brainstorming or marketing drafts. Temperature is not a replacement for clear instructions; it only controls variation around the instructions you already supplied.

Make Output Machine-Readable

Natural-language responses are easy for people to read but fragile for applications. If your code needs to branch on a result, request a fixed schema. State that the response must contain only the requested JSON and define allowed values.

For a ticket router, add: Return exactly one JSON object. urgency must be one of low, medium, high, or critical. team must be one of billing, technical_support, account, or general. If the ticket lacks evidence, use low confidence rather than guessing.

Then validate the response in your application before acting on it. A model can still return malformed output, especially after upstream changes or unusual inputs. Parsing, schema validation, retries, and a safe fallback are part of prompt engineering in production, not optional cleanup work.

Use Examples Only When Rules Are Not Enough

Few-shot prompting means including examples of input and desired output. It is useful when labels are ambiguous or formatting is complex. Keep examples short and representative. One billing example and one technical example are usually more valuable than ten nearly identical examples.

Do not include examples that conflict with your written rules. Models will try to reconcile both, and inconsistent demonstrations frequently cause inconsistent results.

Test Prompts Like Application Code

Create a small evaluation set before deploying: normal inputs, incomplete inputs, very long inputs, adversarial text, and cases where the correct answer is “unknown.” Store the expected properties rather than demanding identical wording. For example, verify that every routing result parses as JSON, uses an allowed team value, and never exposes data not present in the ticket.

Track latency, token use, parse failures, and task accuracy by prompt version and model. A cheaper model may be ideal for high-volume classification, while a stronger model may be worth using for complex reasoning. 59API makes this experimentation more accessible with economical pay-as-you-go access, compatibility with tools such as Claude Code and Codex, and a referral rebate for eligible sharing. Sign up for 59API when you are ready to compare prompt quality and cost in your existing development workflow.

Precios · Docs

¿Listo para empezar?

Conecta Claude y GPT en minutos a los precios más bajos, sin recortes. Regístrate para obtener tu clave API.

Registro gratis