# Quickstart tutorial generative search exception on max\_token using Python

**URL:** <https://forum.weaviate.io/t/quickstart-tutorial-generative-search-exception-on-max-token-using-python/5434>\
**Category:** Support\
**Tags:** python, technical\
**Created:** [October 15, 2024, 5:52pm UTC](https://forum.weaviate.io/t/quickstart-tutorial-generative-search-exception-on-max-token-using-python/5434 "2024-10-15T17:52:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Blom](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/chris_blom/32/2558_2.png) [@Chris\_Blom](https://forum.weaviate.io/u/Chris_Blom)\
**Post date:** [October 15, 2024, 5:52pm UTC](https://forum.weaviate.io/t/quickstart-tutorial-generative-search-exception-on-max-token-using-python/5434/1 "2024-10-15T17:52:18Z")

</div>

Hi, I am new to Weaviate and followed the QuickStart steps exactly but ran into the following exception. Any help is appreciated!

### Description

Implementing the [QuickStart](https://weaviate.io/developers/weaviate/quickstart) on WCD with Python gives the following exception when doing a generative search:

weaviate.exceptions.WeaviateQueryError: Query call with protocol GRPC search failed with message \<AioRpcError of RPC that terminated with:  
status = StatusCode.UNKNOWN  
details = “connection to: OpenAI API failed with status: 400 request-id: req\_4419cf1a05ed4792171000454b82a998 error: max\_tokens is too large: 4097. This model supports at most 4096 completion tokens, whereas you provided 4097.”  
debug\_error\_string = “UNKNOWN:Error received from peer {created\_time:“2024-10-15T19:41:41.686614+02:00”, grpc\_status:2, grpc\_message:“connection to: OpenAI API failed with status: 400 request-id: req\_4419cf1a05ed4792171000454b82a998 error: max\_tokens is too large: 4097. This model supports at most 4096 completion tokens, whereas you provided 4097.”}”

### Server Setup Information

WCS Sandbox standard

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [October 15, 2024, 7:04pm UTC](https://forum.weaviate.io/t/quickstart-tutorial-generative-search-exception-on-max-token-using-python/5434/2 "2024-10-15T19:04:55Z")

</div>

hi @Chris_Blom !!

Welcome to our community 🤗

This is a known issue that was already tackled here:

> <https://github.com/weaviate/weaviate/pull/5982>
>
> \### What's being changed:
> 
> See Slack discussion: \[Link\]( https://weaviate-org.…slack.com/archives/C04AT0Y52E6/p1728641537952229?thread\_ts=1728635290.391309&cid=C04AT0Y52E6)
> 
> \- Updated the default model for generative-openai (gpt-3.5-turbo) to reflect the maxTokens of 4096 and resolve error \`max\_tokens is too large: 4097. This model supports at most 4096 completion tokens, whereas you provided 4097.\`
> \- Added gpt-4o-mini to available models list
> \- gpt-4o was also brought in due to being available in stable/v1.26 - can be edited if needed or merged if this is okay
> 
> Documentation change request: would be worth updating available model list here: \[Available Models - openai-generative\](https://weaviate.io/developers/weaviate/model-providers/openai/generative#available-models)
> 
> \### Review checklist
> 
> \- \[\] Documentation has been updated, if necessary. Link to changed documentation:
> \- \[\] Chaos pipeline run or not necessary. Link to pipeline:
> \- \[\] All new code is covered by tests where it is reasonable.
> \- \[\] Performance tests have been run or not necessary.
> 
> Uncomment the following section if this PR requires changes in related projects (e.g., documentation, client libraries).
> 
> GitHub actions will automatically create an issue in the corresponding repository for each checked box below. (See \`.github/workflows/create-cross-functional-issues.yml\`)
> 
> \### Cross-functional impact
> 
> \- \[x\] This change requires public documentation (weaviate-io) to be updated. Check the box to automatically create a corresponding issue.
> \- Does it require a change in the client libraries? If yes, please check the boxes for the affected client libraries.
> - \[\] Python (weaviate-python-client)
> - \[\] JavaScript/TypeScript (typescript-client)
> - \[\] Go (weaviate-go-client)
> - \[\] Java (java-client)

It seems there was a change in OpenAI Api 🤔

this should be a workaround, but it’s also falling into the same issue:

```python
client.collections.delete("Test")
collection = client.collections.create(
    name="Test",
    vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai(),
    generative_config=wvc.config.Configure.Generative.openai(model="gpt-3.5-turbo", max_tokens=4096),
)

collection.data.insert({
        "text": "something about dogs",
    }
)
collection.data.insert({
        "text": "something about cats",
    }
)

results = collection.generate.near_text(
    query="animals",
    grouped_task="Create a content with {text}",
    single_prompt="Translate {text} to portuguese"
)

```

I’ll get back here with more information as soon as I get it 🙂

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [October 15, 2024, 7:10pm UTC](https://forum.weaviate.io/t/quickstart-tutorial-generative-search-exception-on-max-token-using-python/5434/3 "2024-10-15T19:10:57Z")

</div>

ps, for now, if you only want to play around you can use the gpt-4 model, like so:

```python
client.collections.delete("Test")
collection = client.collections.create(
    name="Test",
    vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai(),
    generative_config=wvc.config.Configure.Generative.openai(model="gpt-4"),
)

collection.data.insert({
        "text": "something about dogs",
    }
)
collection.data.insert({
        "text": "something about cats",
    }
)

results = collection.generate.near_text(
    query="animals",
    grouped_task="Create a content with {text}",
    single_prompt="Translate {text} to portuguese"
)

```

---

<div class="post-metadata">

**Author:** ![Chris\_Blom](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/chris_blom/32/2558_2.png) [@Chris\_Blom](https://forum.weaviate.io/u/Chris_Blom)\
**Post date:** [October 16, 2024, 6:03am UTC](https://forum.weaviate.io/t/quickstart-tutorial-generative-search-exception-on-max-token-using-python/5434/4 "2024-10-16T06:03:07Z")

</div>

Hi Duda, thanks for the quick reply and I’ll change to gpt-4. regards, Chris

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [October 16, 2024, 11:59am UTC](https://forum.weaviate.io/t/quickstart-tutorial-generative-search-exception-on-max-token-using-python/5434/5 "2024-10-16T11:59:14Z")

</div>

Great! A new patch is being released to address this change in apis.

it should be released probably today.

Thanks!
