Ignora e passa al contenuto principale

Questo browser non è più supportato.

Esegui l'aggiornamento a Microsoft Edge per sfruttare i vantaggi di funzionalità più recenti, aggiornamenti della sicurezza e supporto tecnico.

Scarica Microsoft Edge Scopri di più su Internet Explorer e Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Embeddings

Create an embedding

POST /openai/v1/embeddings

Creates an embedding from the supplied request.

Corpo della richiesta

The request body.

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

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.

Uno dei seguenti:
string
string[]
OpenAI.integer[]
OpenAI.integer[][]
model string | enum necessario

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.

Uno qualsiasi dei seguenti:
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.

Risposte

The request has succeeded.

Corpo

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

The list of embeddings generated by the model.

model string necessario

The name of the model used to generate the embedding.

object enum necessario

The object type, which is always "list".

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

Client error

Corpo

Content-Type: application/json
error OpenAI.Error necessario
code string | null necessario
message string necessario
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Uno qualsiasi dei seguenti:
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 necessario

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Corpo

Content-Type: application/json
error OpenAI.Error necessario
code string | null necessario
message string necessario
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Uno qualsiasi dei seguenti:
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 necessario

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Richiedi

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
  }
}
it-it
Scelte sulla privacy
  • Dichiarazione di non responsabilità relativa all'intelligenza artificiale
  • Versioni precedenti
  • Blog
  • Collabora
  • Riservatezza
  • Privacy dei dati sanitari dei consumatori
  • Condizioni per l'utilizzo
  • Accessibilità
  • Marchi
  • © Microsoft 2026