# How to increase tokens text generation API

**URL:** <https://discuss.huggingface.co/t/how-to-increase-tokens-text-generation-api/22192>\
**Category:** Intermediate\
**Created:** [August 27, 2022, 10:53am UTC](https://discuss.huggingface.co/t/how-to-increase-tokens-text-generation-api/22192 "2022-08-27T10:53:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeyBeez](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mikeybeez/32/21067_2.png) [@MikeyBeez](https://discuss.huggingface.co/u/MikeyBeez)\
**Post date:** [August 27, 2022, 10:53am UTC](https://discuss.huggingface.co/t/how-to-increase-tokens-text-generation-api/22192/1 "2022-08-27T10:53:04Z")

</div>

I can only get a few tokens back from an API call; so I tried this code, but it didn’t work. How can I tune the length of the tokens returned?

```auto
def query(payload):
    data = json.dumps(payload)
    response = requests.request("POST", API_URL, headers=headers, data=data)
    return json.loads(response.content.decode("utf-8"))
data = query(
    {

        "inputs": "Albert Einstein was",
        "parameters": {max_new_tokens = 100}
    }
)
print(data)

```

---

<div class="post-metadata">

**Author:** ![MikeyBeez](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mikeybeez/32/21067_2.png) [@MikeyBeez](https://discuss.huggingface.co/u/MikeyBeez)\
**Post date:** [August 28, 2022, 1:10am UTC](https://discuss.huggingface.co/t/how-to-increase-tokens-text-generation-api/22192/2 "2022-08-28T01:10:41Z")

</div>

Solved it! It’s just bad python syntax. Duh!

```auto
def query(payload):
    data = json.dumps(payload)
    response = requests.request("POST", API_URL, headers=headers, data=data)
    return json.loads(response.content.decode("utf-8"))
data = query(
# {
#
# "inputs": "Albert Einstein was",
# "parameters": { "min_length" : 100,
# "max_length" : 100 }
# }
    {

        "inputs": "Albert Einstein was",
        "parameters": { "min_length" : 100,
             "max_new_tokens" : 100 }
    }
)
print(data)
print("Time consumed in working: ",end - start)

```
