# How to generate text

In order to generate text using the API today you will need two pieces of information:

1. &#x20;The sentence premise ID
2. A dictionary of variables that contain contact data if you are generating a sentence or the inputs if you are generating an email.

The example below will illustrate the process for generating a **sentence premise** however the process is the same for email generation.

{% hint style="info" %}
Premises can only be created in your dashboard.
{% endhint %}

Let's start by grabbing our sentence ID.

You can filter for sentence premise IDs by using the ['list all premises'](/api/premises/list-all-premises.md) or '[get premise' endpoints](/api/premises/get-a-premise.md)'. This is what the object returned will look like.

```
# Sentence premise object
{
    "data": {
        "id": 19,
        "premise_name": "Contact",
        "required_variables": [
            "person_description", "first_name"
        ],
        "profile_name": "Copyfactory"
        "premise_type": "sentence"
    }
}
```

The 'required variables' key contains an array of fields that need data for this sentence premise to generate.

```
"required_variables": ["person_description", "first_name"],
```

In the example above we would therefore need to create a dictionary with the keys 'person\_descriptio&#x6E;*'* and *'*&#x66;irst\_name' where the values are the contact data inputs.

```
{
	"first_name": "Mark",
	"person_description": "This is my description of someone..."
}
```

Once we have these two pieces of information the last step is to make a POST request to the generate sentence endpoint.

An example in python could look like this:

```
import requests
import json

url = "https://app.copyfactory.io/api/v2/generate/"

payload = json.dumps({
  "premise_id": 19, # taken from sentence premise ID above
  "variables": {
    "first_name": "Mark",
    "person_description":"This is my description of someone..."
  }
})

headers = {
  'Authorization': 'API-KEY',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% hint style="info" %}
If you get an error try looking at the meta data to see the related objects.
{% endhint %}

And you are done!

Consult the text generation object by going to the link below.

{% content-ref url="/pages/Z5B2SJ1ac6bwDrxqa1ir" %}
[Generate text](/api/generations/generate-text.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.copyfactory.io/text-generation-tutorials/how-to-generate-text.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
