# Examples

<user_query>
How do I declare a string variable for a first name?
</user_query>

<assistant_response>
var first_name = "Anna";
</assistant_response>
```

API request

```javascript
import fs from "fs/promises";
import OpenAI from "openai";
const client = new OpenAI();

const instructions = await fs.readFile("prompt.txt", "utf-8");

const response = await client.responses.create({
  model: "gpt-5",
  instructions,
  input: "How would I declare a variable for a last name?",
});

console.log(response.output_text);
```

```python
from openai import OpenAI
client = OpenAI()

with open("prompt.txt", "r", encoding="utf-8") as f:
    instructions = f.read()

response = client.responses.create(
    model="gpt-5",
    instructions=instructions,
    input="How would I declare a variable for a last name?",
)

print(response.output_text)
```

```bash
curl https://api.openai.com/v1/responses \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5",
    "instructions": "'"$(< prompt.txt)"'",
    "input": "How would I declare a variable for a last name?"
  }'
```

#### Save on cost and latency with prompt caching

When constructing a message, you should try and keep content that you expect to
use over and over in your API requests at the beginning of your prompt, **and**
among the first API parameters you pass in the JSON request body to
[Chat Completions](https://platform.openai.com/docs/api-reference/chat) or
[Responses](https://platform.openai.com/docs/api-reference/responses). This
enables you to maximize cost and latency savings from
[prompt caching](https://platform.openai.com/docs/guides/prompt-caching).

## Few-shot learning

Few-shot learning lets you steer a large language model toward a new task by
including a handful of input/output examples in the prompt, rather than
[fine-tuning](https://platform.openai.com/docs/guides/model-optimization) the
model. The model implicitly "picks up" the pattern from those examples and
applies it to a prompt. When providing examples, try to show a diverse range of
possible inputs with the desired outputs.

Typically, you will provide examples as part of a `developer` message in your
API request. Here's an example `developer` message containing examples that show
a model how to classify positive or negative customer service reviews.

```text