Przejdź do głównej zawartości

Ta przeglądarka nie jest już obsługiwana.

Przejdź na przeglądarkę Microsoft Edge, aby korzystać z najnowszych funkcji, aktualizacji zabezpieczeń i pomocy technicznej.

Pobieranie przeglądarki Microsoft Edge Więcej informacji o przeglądarkach Internet Explorer i Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Embeddings

Create an embedding

POST /openai/v1/embeddings

Creates an embedding from the supplied request.

Treść żądania

The request body.

Content-Type: application/json
input string | string[] | OpenAI.integer[] | OpenAI.integer[][] wymagane

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 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.

Jedna z następujących:
string
string[]
OpenAI.integer[]
OpenAI.integer[][]
model string | enum wymagane

ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.

Którekolwiek z poniższych:
string
enum
text-embedding-ada-002text-embedding-3-smalltext-embedding-3-large
encoding_format enum

The format to return the embeddings in. Can be either float or base64.

floatbase64
dimensions integer
user string

A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Odpowiedzi

The request has succeeded.

Treść

Content-Type: application/json
data OpenAI.Embedding[] wymagane

The list of embeddings generated by the model.

model string wymagane

The name of the model used to generate the embedding.

object enum wymagane

The object type, which is always "list".

list
usage OpenAI.CreateEmbeddingResponseUsage wymagane
prompt_tokens integer wymagane
total_tokens integer wymagane

Client error

Treść

Content-Type: application/json
error OpenAI.Error wymagane
code string | null wymagane
message string wymagane
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Którekolwiek z poniższych:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string wymagane

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Treść

Content-Type: application/json
error OpenAI.Error wymagane
code string | null wymagane
message string wymagane
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Którekolwiek z poniższych:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string wymagane

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Żądanie

curl https://api.openai.com/v1/embeddings \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "The food was delicious and the waiter...",
    "model": "text-embedding-ada-002",
    "encoding_format": "float"
  }'
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
create_embedding_response = client.embeddings.create(
    input="The quick brown fox jumped over the lazy dog",
    model="text-embedding-3-small",
)
print(create_embedding_response.data)
import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const embedding = await openai.embeddings.create({
    model: "text-embedding-ada-002",
    input: "The quick brown fox jumped over the lazy dog",
    encoding_format: "float",
  });

  console.log(embedding);
}

main();
using System;

using OpenAI.Embeddings;

EmbeddingClient client = new(
    model: "text-embedding-3-small",
    apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")
);

OpenAIEmbedding embedding = client.GenerateEmbedding(input: "The quick brown fox jumped over the lazy dog");
ReadOnlyMemory<float> vector = embedding.ToFloats();

for (int i = 0; i < vector.Length; i++)
{
    Console.WriteLine($"  [{i,4}] = {vector.Span[i]}");
}
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});

const createEmbeddingResponse = await client.embeddings.create({
  input: 'The quick brown fox jumped over the lazy dog',
  model: 'text-embedding-3-small',
});

console.log(createEmbeddingResponse.data);
package main

import (
    "context"
    "fmt"

    "github.com/openai/openai-go"
    "github.com/openai/openai-go/option"
)

func main() {
    client := openai.NewClient(
        option.WithAPIKey("My API Key"),
    )
    createEmbeddingResponse, err := client.Embeddings.New(context.TODO(), openai.EmbeddingNewParams{
        Input: openai.EmbeddingNewParamsInputUnion{
            OfString: openai.String("The quick brown fox jumped over the lazy dog"),
        },
        Model: openai.EmbeddingModelTextEmbedding3Small,
    })
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", createEmbeddingResponse.Data)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.embeddings.CreateEmbeddingResponse;
import com.openai.models.embeddings.EmbeddingCreateParams;
import com.openai.models.embeddings.EmbeddingModel;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        EmbeddingCreateParams params = EmbeddingCreateParams.builder()
            .input("The quick brown fox jumped over the lazy dog")
            .model(EmbeddingModel.TEXT_EMBEDDING_3_SMALL)
            .build();
        CreateEmbeddingResponse createEmbeddingResponse = client.embeddings().create(params);
    }
}
require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

create_embedding_response = openai.embeddings.create(
  input: "The quick brown fox jumped over the lazy dog",
  model: :"text-embedding-3-small"
)

puts(create_embedding_response)

Response

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        -0.009327292,
        .... (1536 floats total for ada-002)
        -0.0028842222,
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-ada-002",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}
pl-pl
Wybrane przez Ciebie opcje dotyczące prywatności
  • Zastrzeżenie dotyczące sztucznej inteligencji
  • Poprzednie wersje
  • Blog
  • Współtworzenie
  • Prywatność
  • Prywatność kondycji konsumenta
  • Warunki użytkowania
  • Znaki towarowe
  • © Microsoft 2026