> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.meshapi.ai/llms.txt.
> For full documentation content, see https://developers.meshapi.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.meshapi.ai/_mcp/server.

# Create Embeddings

POST https://api.meshapi.ai/v1/embeddings
Content-Type: application/json

Reference: https://developers.meshapi.ai/api-reference/mesh-api/embeddings/create-embeddings-v-1-embeddings-post

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: openapi
  version: 1.0.0
paths:
  /v1/embeddings:
    post:
      operationId: create-embeddings-v-1-embeddings-post
      summary: Create Embeddings
      tags:
        - subpackage_embeddings
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                description: Any type
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EmbeddingsRequest'
servers:
  - url: https://api.meshapi.ai
components:
  schemas:
    EmbeddingsRequestInput:
      oneOf:
        - type: string
        - type: array
          items:
            type: string
        - type: array
          items:
            type: integer
        - type: array
          items:
            type: array
            items:
              type: integer
      description: >-
        Text(s) to embed. Accepts a string, list of strings, list of token IDs,
        or a list of token ID lists.
      title: EmbeddingsRequestInput
    EmbeddingsRequestEncodingFormat:
      type: string
      enum:
        - float
        - base64
      description: Format of the returned embedding. Defaults to `float`.
      title: EmbeddingsRequestEncodingFormat
    ProviderPreferencesDataCollection:
      type: string
      enum:
        - allow
        - deny
      description: Control whether the provider may use the request for training.
      title: ProviderPreferencesDataCollection
    ProviderPreferences:
      type: object
      properties:
        order:
          type:
            - array
            - 'null'
          items:
            type: string
          description: Preferred provider order, e.g. ['perplexity', 'openai'].
        allow_fallbacks:
          type:
            - boolean
            - 'null'
          description: Whether to fall back to other providers if the first is unavailable.
        require_parameters:
          type:
            - boolean
            - 'null'
          description: Only use providers that support all requested parameters.
        data_collection:
          oneOf:
            - $ref: '#/components/schemas/ProviderPreferencesDataCollection'
            - type: 'null'
          description: Control whether the provider may use the request for training.
      description: OpenRouter provider routing preferences.
      title: ProviderPreferences
    EmbeddingsRequestProvider:
      oneOf:
        - type: string
        - $ref: '#/components/schemas/ProviderPreferences'
      description: >-
        Provider routing preferences. Pass a provider slug string (e.g.
        `'perplexity'`) or a `ProviderPreferences` object to control fallback
        and ordering behaviour.
      title: EmbeddingsRequestProvider
    EmbeddingsRequest:
      type: object
      properties:
        model:
          type:
            - string
            - 'null'
          description: Model ID to use for embedding, e.g. `perplexity/pplx-embed-v1-4b`.
        input:
          $ref: '#/components/schemas/EmbeddingsRequestInput'
          description: >-
            Text(s) to embed. Accepts a string, list of strings, list of token
            IDs, or a list of token ID lists.
        dimensions:
          type:
            - integer
            - 'null'
          description: >-
            Number of dimensions for the output embedding vector
            (model-dependent).
        encoding_format:
          oneOf:
            - $ref: '#/components/schemas/EmbeddingsRequestEncodingFormat'
            - type: 'null'
          description: Format of the returned embedding. Defaults to `float`.
        input_type:
          type:
            - string
            - 'null'
          description: >-
            Intended use of the embedding, e.g. `query` or `document`. Some
            models use this to apply asymmetric embedding.
        provider:
          oneOf:
            - $ref: '#/components/schemas/EmbeddingsRequestProvider'
            - type: 'null'
          description: >-
            Provider routing preferences. Pass a provider slug string (e.g.
            `'perplexity'`) or a `ProviderPreferences` object to control
            fallback and ordering behaviour.
        user:
          type:
            - string
            - 'null'
          description: End-user identifier for abuse monitoring (forwarded to OpenRouter).
      required:
        - input
      description: >-
        Request body for `POST /v1/embeddings`.


        Mirrors the OpenAI / OpenRouter embeddings API. The `input` field
        accepts

        four shapes:


        - **string** — a single text to embed

        - **list[string]** — a batch of texts

        - **list[int]** — a single pre-tokenised input (token IDs)

        - **list[list[int]]** — a batch of pre-tokenised inputs
      title: EmbeddingsRequest
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

```

## SDK Code Examples

```python
import requests

url = "https://api.meshapi.ai/v1/embeddings"

payload = {
    "input": "The quick brown fox jumps over the lazy dog",
    "model": "openai/text-embedding-3-small",
    "dimensions": 1536,
    "encoding_format": "float",
    "input_type": "document",
    "provider": "openai",
    "user": "user_1234567890"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.meshapi.ai/v1/embeddings';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"input":"The quick brown fox jumps over the lazy dog","model":"openai/text-embedding-3-small","dimensions":1536,"encoding_format":"float","input_type":"document","provider":"openai","user":"user_1234567890"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.meshapi.ai/v1/embeddings"

	payload := strings.NewReader("{\n  \"input\": \"The quick brown fox jumps over the lazy dog\",\n  \"model\": \"openai/text-embedding-3-small\",\n  \"dimensions\": 1536,\n  \"encoding_format\": \"float\",\n  \"input_type\": \"document\",\n  \"provider\": \"openai\",\n  \"user\": \"user_1234567890\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.meshapi.ai/v1/embeddings")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"input\": \"The quick brown fox jumps over the lazy dog\",\n  \"model\": \"openai/text-embedding-3-small\",\n  \"dimensions\": 1536,\n  \"encoding_format\": \"float\",\n  \"input_type\": \"document\",\n  \"provider\": \"openai\",\n  \"user\": \"user_1234567890\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.meshapi.ai/v1/embeddings")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"input\": \"The quick brown fox jumps over the lazy dog\",\n  \"model\": \"openai/text-embedding-3-small\",\n  \"dimensions\": 1536,\n  \"encoding_format\": \"float\",\n  \"input_type\": \"document\",\n  \"provider\": \"openai\",\n  \"user\": \"user_1234567890\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.meshapi.ai/v1/embeddings', [
  'body' => '{
  "input": "The quick brown fox jumps over the lazy dog",
  "model": "openai/text-embedding-3-small",
  "dimensions": 1536,
  "encoding_format": "float",
  "input_type": "document",
  "provider": "openai",
  "user": "user_1234567890"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.meshapi.ai/v1/embeddings");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"input\": \"The quick brown fox jumps over the lazy dog\",\n  \"model\": \"openai/text-embedding-3-small\",\n  \"dimensions\": 1536,\n  \"encoding_format\": \"float\",\n  \"input_type\": \"document\",\n  \"provider\": \"openai\",\n  \"user\": \"user_1234567890\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "input": "The quick brown fox jumps over the lazy dog",
  "model": "openai/text-embedding-3-small",
  "dimensions": 1536,
  "encoding_format": "float",
  "input_type": "document",
  "provider": "openai",
  "user": "user_1234567890"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.meshapi.ai/v1/embeddings")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```