{
  "openapi": "3.1.0",
  "info": {
    "title": "Embeddings API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.cometapi.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/embeddings": {
      "post": {
        "summary": "Create Embeddings",
        "operationId": "createEmbeddings",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "input"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "The embedding model to use. See the [Models page](/overview/models) for current embedding model IDs.",
                    "example": "text-embedding-3-small"
                  },
                  "input": {
                    "oneOf": [
                      {
                        "type": "string",
                        "description": "A single text string to embed."
                      },
                      {
                        "type": "array",
                        "description": "An array of strings to embed in a single request. Each string can be up to 8,191 tokens.",
                        "items": {
                          "type": "string"
                        }
                      },
                      {
                        "type": "array",
                        "description": "An array of token arrays.",
                        "items": {
                          "type": "array",
                          "items": {
                            "type": "integer"
                          }
                        }
                      }
                    ],
                    "description": "The text to embed. Can be a single string, an array of strings, or an array of token arrays. Each input must not exceed the model's maximum token limit (8,191 tokens for `text-embedding-3-*` models)."
                  },
                  "encoding_format": {
                    "type": "string",
                    "description": "The format of the returned embedding vectors. `float` returns an array of floating-point numbers. `base64` returns a base64-encoded string representation, which can reduce response size for large batches.",
                    "enum": [
                      "float",
                      "base64"
                    ],
                    "default": "float"
                  },
                  "dimensions": {
                    "type": "integer",
                    "description": "The number of dimensions for the output embedding vector. Only supported by `text-embedding-3-*` models. Reducing dimensions can lower storage costs while maintaining most of the embedding's utility.",
                    "minimum": 1
                  },
                  "user": {
                    "type": "string",
                    "description": "A unique identifier for your end-user, which can help monitor and detect abuse."
                  }
                }
              },
              "examples": {
                "Single Text": {
                  "summary": "Single Text",
                  "value": {
                    "model": "text-embedding-3-small",
                    "input": "The food was delicious and the waiter was friendly."
                  }
                },
                "Batch Input": {
                  "summary": "Batch Input",
                  "value": {
                    "model": "text-embedding-3-small",
                    "input": [
                      "Hello world",
                      "How are you?",
                      "Embedding example"
                    ],
                    "encoding_format": "float"
                  }
                },
                "With Dimensions": {
                  "summary": "Reduced Dimensions",
                  "value": {
                    "model": "text-embedding-3-small",
                    "input": "Search query text",
                    "dimensions": 256
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A list of embedding vectors for the input text(s).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "description": "The object type, always `list`.",
                      "enum": [
                        "list"
                      ],
                      "example": "list"
                    },
                    "data": {
                      "type": "array",
                      "description": "An array of embedding objects, one per input text. When multiple inputs are provided, results are returned in the same order as the input.",
                      "items": {
                        "type": "object",
                        "properties": {
                          "object": {
                            "type": "string",
                            "description": "The object type, always `embedding`.",
                            "enum": [
                              "embedding"
                            ],
                            "example": "embedding"
                          },
                          "index": {
                            "type": "integer",
                            "description": "The index of this embedding in the input array (starting from 0).",
                            "example": 0
                          },
                          "embedding": {
                            "type": "array",
                            "description": "The embedding vector as an array of floating-point numbers. The length depends on the model and `dimensions` parameter.",
                            "items": {
                              "type": "number"
                            },
                            "example": [
                              -0.0021,
                              -0.0491,
                              0.0209,
                              0.0314,
                              -0.0453
                            ]
                          }
                        }
                      }
                    },
                    "model": {
                      "type": "string",
                      "description": "The model used to generate the embeddings.",
                      "example": "text-embedding-3-small"
                    },
                    "usage": {
                      "type": "object",
                      "description": "Token usage statistics for this request.",
                      "properties": {
                        "prompt_tokens": {
                          "type": "integer",
                          "description": "The number of tokens in the input text(s).",
                          "example": 2
                        },
                        "total_tokens": {
                          "type": "integer",
                          "description": "The total number of tokens processed (same as `prompt_tokens` for embeddings).",
                          "example": 2
                        }
                      }
                    }
                  }
                },
                "example": {
                  "object": "list",
                  "data": [
                    {
                      "object": "embedding",
                      "index": 0,
                      "embedding": [
                        -0.0021,
                        -0.0491,
                        0.0209,
                        0.0314,
                        -0.0453
                      ]
                    }
                  ],
                  "model": "text-embedding-3-small",
                  "usage": {
                    "prompt_tokens": 2,
                    "total_tokens": 2
                  }
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Python",
            "label": "Single Text",
            "source": "import os\nfrom openai import OpenAI\n\nclient = OpenAI(\n    base_url=\"https://api.cometapi.com/v1\",\n    api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nresponse = client.embeddings.create(\n    model=\"text-embedding-3-small\",\n    input=\"The food was delicious and the waiter was friendly.\",\n)\n\nprint(response.data[0].embedding[:5])  # First 5 dimensions\nprint(f\"Dimensions: {len(response.data[0].embedding)}\")\n"
          },
          {
            "lang": "Python",
            "label": "Batch Input",
            "source": "import os\nfrom openai import OpenAI\n\nclient = OpenAI(\n    base_url=\"https://api.cometapi.com/v1\",\n    api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\nresponse = client.embeddings.create(\n    model=\"text-embedding-3-small\",\n    input=[\"Hello world\", \"How are you?\", \"Embedding example\"],\n)\n\nfor item in response.data:\n    print(f\"Index {item.index}: {len(item.embedding)} dimensions\")\n"
          },
          {
            "lang": "Python",
            "label": "Reduced Dimensions",
            "source": "import os\nfrom openai import OpenAI\n\nclient = OpenAI(\n    base_url=\"https://api.cometapi.com/v1\",\n    api_key=os.environ[\"COMETAPI_KEY\"],\n)\n\n# Use fewer dimensions to reduce storage costs\nresponse = client.embeddings.create(\n    model=\"text-embedding-3-small\",\n    input=\"Search query text\",\n    dimensions=256,\n)\n\nprint(f\"Dimensions: {len(response.data[0].embedding)}\")  # 256\n"
          },
          {
            "lang": "JavaScript",
            "label": "Single Text",
            "source": "import OpenAI from \"openai\";\n\nconst client = new OpenAI({\n    baseURL: \"https://api.cometapi.com/v1\",\n    apiKey: process.env.COMETAPI_KEY,\n});\n\nconst response = await client.embeddings.create({\n    model: \"text-embedding-3-small\",\n    input: \"The food was delicious and the waiter was friendly.\",\n});\n\nconsole.log(response.data[0].embedding.slice(0, 5));\nconsole.log(`Dimensions: ${response.data[0].embedding.length}`);\n"
          },
          {
            "lang": "JavaScript",
            "label": "Batch Input",
            "source": "import OpenAI from \"openai\";\n\nconst client = new OpenAI({\n    baseURL: \"https://api.cometapi.com/v1\",\n    apiKey: process.env.COMETAPI_KEY,\n});\n\nconst response = await client.embeddings.create({\n    model: \"text-embedding-3-small\",\n    input: [\"Hello world\", \"How are you?\", \"Embedding example\"],\n});\n\nfor (const item of response.data) {\n    console.log(`Index ${item.index}: ${item.embedding.length} dimensions`);\n}\n"
          },
          {
            "lang": "JavaScript",
            "label": "Reduced Dimensions",
            "source": "import OpenAI from \"openai\";\n\nconst client = new OpenAI({\n    baseURL: \"https://api.cometapi.com/v1\",\n    apiKey: process.env.COMETAPI_KEY,\n});\n\n// Use fewer dimensions to reduce storage costs\nconst response = await client.embeddings.create({\n    model: \"text-embedding-3-small\",\n    input: \"Search query text\",\n    dimensions: 256,\n});\n\nconsole.log(`Dimensions: ${response.data[0].embedding.length}`); // 256\n"
          },
          {
            "lang": "Shell",
            "label": "Single Text",
            "source": "curl https://api.cometapi.com/v1/embeddings \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -d '{\n    \"model\": \"text-embedding-3-small\",\n    \"input\": \"The food was delicious and the waiter was friendly.\"\n  }'\n"
          },
          {
            "lang": "Shell",
            "label": "Batch Input",
            "source": "curl https://api.cometapi.com/v1/embeddings \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -d '{\n    \"model\": \"text-embedding-3-small\",\n    \"input\": [\"Hello world\", \"How are you?\", \"Embedding example\"]\n  }'\n"
          },
          {
            "lang": "Shell",
            "label": "Reduced Dimensions",
            "source": "curl https://api.cometapi.com/v1/embeddings \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -d '{\n    \"model\": \"text-embedding-3-small\",\n    \"input\": \"Search query text\",\n    \"dimensions\": 256\n  }'\n"
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer token authentication. Use your CometAPI key."
      }
    }
  }
}
