# Issue creating embedding from Python lib

**URL:** <https://community.openai.com/t/issue-creating-embedding-from-python-lib/479735>\
**Category:** API\
**Created:** [November 7, 2023, 6:47pm UTC](https://community.openai.com/t/issue-creating-embedding-from-python-lib/479735 "2023-11-07T18:47:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cliff.rosen](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/cliff.rosen/32/32920_2.png) [@cliff.rosen](https://community.openai.com/u/cliff.rosen)\
**Post date:** [November 7, 2023, 6:47pm UTC](https://community.openai.com/t/issue-creating-embedding-from-python-lib/479735/1 "2023-11-07T18:47:33Z")

</div>

After updating the openai Python module, I found that my embedding code is no longer working. So I went to the documentation [here](https://platform.openai.com/docs/guides/embeddings/use-cases) to verify proper syntax with this update and found the following example:

```auto
res = client.embeddings.create(input = [text], model=model)
return res['data'][0]['embedding']

```

When I try this, however, I get the following error:

> TypeError: ‘CreateEmbeddingResponse’ object is not subscriptable

which I can get around by accessing the embedding using dot notation :

```auto
return res.data[0].embedding

```

Is this a glitch with the documentation and/or the new openai module, or is something funky with my environment?

---

<div class="post-metadata">

**Author:** ![joshatrezolvedotai](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/joshatrezolvedotai/32/448547_2.png) [@joshatrezolvedotai](https://community.openai.com/u/joshatrezolvedotai)\
**Post date:** [November 8, 2023, 12:40am UTC](https://community.openai.com/t/issue-creating-embedding-from-python-lib/479735/2 "2023-11-08T00:40:59Z")

</div>

Been foolin’ with this crap all day. Not just you!

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [November 8, 2023, 12:56am UTC](https://community.openai.com/t/issue-creating-embedding-from-python-lib/479735/3 "2023-11-08T00:56:12Z")

</div>

You might start at a well-disguised migration guide:

> **[v1.0.0 Beta · openai openai-python · Discussion #631](https://github.com/openai/openai-python/discussions/631)**
>
> Importantv1.0.0 is live! Get started by following the migration guide here: #742

Then read about the changes from prior dictionary-like openai objects:

## [Using types](https://github.com/openai/openai-python/tree/release-please--branches--main--changes--next#using-types)

Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev), which provide helper methods for things like serializing back into JSON ([v1](https://docs.pydantic.dev/1.10/usage/models/), [v2](https://docs.pydantic.dev/latest/usage/serialization/)). To get a dictionary, call `model.model_dump()`.

Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.

## [Pagination](https://github.com/openai/openai-python/tree/release-please--branches--main--changes--next#pagination)

List methods in the OpenAI API are paginated.

This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:

```auto
import openai

client = OpenAI()

all_jobs = []
# Automatically fetches more pages as needed.
for job in client.fine_tuning.jobs.list(
    limit=20,
):
    # Do something with job here
    all_jobs.append(job)
print(all_jobs)

```

Heading links are to the “next” branch of python library with readme.

---

<div class="post-metadata">

**Author:** ![3zz3](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/3zz3/32/292204_2.png) [@3zz3](https://community.openai.com/u/3zz3)\
**Post date:** [January 22, 2024, 2:43pm UTC](https://community.openai.com/t/issue-creating-embedding-from-python-lib/479735/4 "2024-01-22T14:43:14Z")

</div>

I’ve been facing the same issue as well - not entirely sure why. Using the same workaround for the time being

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [January 22, 2024, 2:59pm UTC](https://community.openai.com/t/issue-creating-embedding-from-python-lib/479735/5 "2024-01-22T14:59:44Z")

</div>

The return object from the python API module is no longer just a Python list or dictionary. It is a pydantic _model_ object, with several sub-objects depending on the API request type.

That means that it cannot be parsed by dictionary methods such as `api_dictionary['dict_key']` (the “not subscriptable” error), but instead has its own methods for accessing data or dumping contents.
