SPB Git

Repository Public

create.md 4.5 KB 178 lines markdown

1> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.23## Create embeddings45**post** `/embeddings`67Creates an embedding vector representing the input text.89### Body Parameters1011- `input: string or array of string or array of number or array of array of number`1213  Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for all embedding models), cannot be an empty string, and any array must be 2048 dimensions or less. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens. In addition to the per-input token limit, all embedding models enforce a maximum of 300,000 tokens summed across all inputs in a single request.1415  - `String = string`1617    The string that will be turned into an embedding.1819  - `Array = array of string`2021    The array of strings that will be turned into an embedding.2223  - `Array = array of number`2425    The array of integers that will be turned into an embedding.2627  - `Array = array of array of number`2829    The array of arrays containing integers that will be turned into an embedding.3031- `model: string or EmbeddingModel`3233  ID of the model to use. You can use the [List models](/api/reference/resources/models/methods/list) API to see all of your available models, or see our [Model overview](/api/docs/models) for descriptions of them.3435  - `string`3637  - `EmbeddingModel = "text-embedding-ada-002" or "text-embedding-3-small" or "text-embedding-3-large"`3839    - `"text-embedding-ada-002"`4041    - `"text-embedding-3-small"`4243    - `"text-embedding-3-large"`4445- `dimensions: optional number`4647  The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models.4849- `encoding_format: optional "float" or "base64"`5051  The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/).5253  - `"float"`5455  - `"base64"`5657- `user: optional string`5859  A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/api/docs/guides/safety-best-practices#implement-safety-identifiers).6061### Returns6263- `CreateEmbeddingResponse object { data, model, object, usage }`6465  - `data: array of Embedding`6667    The list of embeddings generated by the model.6869    - `embedding: array of number`7071      The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](/api/docs/guides/embeddings).7273    - `index: number`7475      The index of the embedding in the list of embeddings.7677    - `object: "embedding"`7879      The object type, which is always "embedding".8081      - `"embedding"`8283  - `model: string`8485    The name of the model used to generate the embedding.8687  - `object: "list"`8889    The object type, which is always "list".9091    - `"list"`9293  - `usage: object { prompt_tokens, total_tokens }`9495    The usage information for the request.9697    - `prompt_tokens: number`9899      The number of tokens used by the prompt.100101    - `total_tokens: number`102103      The total number of tokens used by the request.104105### Example106107```http108curl https://api.openai.com/v1/embeddings \109    -H 'Content-Type: application/json' \110    -H "Authorization: Bearer $OPENAI_API_KEY" \111    -d '{112          "input": "The quick brown fox jumped over the lazy dog",113          "model": "text-embedding-3-small",114          "encoding_format": "float",115          "user": "user-1234"116        }'117```118119#### Response120121```json122{123  "data": [124    {125      "embedding": [126        0127      ],128      "index": 0,129      "object": "embedding"130    }131  ],132  "model": "model",133  "object": "list",134  "usage": {135    "prompt_tokens": 0,136    "total_tokens": 0137  }138}139```140141### Example142143```http144curl https://api.openai.com/v1/embeddings \145  -H "Authorization: Bearer $OPENAI_API_KEY" \146  -H "Content-Type: application/json" \147  -d '{148    "input": "The food was delicious and the waiter...",149    "model": "text-embedding-ada-002",150    "encoding_format": "float"151  }'152```153154#### Response155156```json157{158  "object": "list",159  "data": [160    {161      "object": "embedding",162      "embedding": [163        0.0023064255,164        -0.009327292,165        .... (1536 floats total for ada-002)166        -0.0028842222,167      ],168      "index": 0169    }170  ],171  "model": "text-embedding-ada-002",172  "usage": {173    "prompt_tokens": 8,174    "total_tokens": 8175  }176}177```178
Files main
Menu

Theme