> 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 AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.meshapi.ai/_mcp/server.

# Chat Completions

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

OpenAI-compatible chat completions endpoint.

Auth:        Authorization: Bearer rsk_<ULID>
Streaming:   set stream=true for SSE chunks
Templates:   set template="name" + variables={...}
Rate limits: RPM and RPD enforced per key via Redis fixed-window counters
Spend cap:   enforced if key.spend_cap_usd is set (soft cap)

Reference: https://developers.meshapi.ai/api-reference/mesh-api/chat/completions-v-1-chat-completions-post

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: openapi
  version: 1.0.0
paths:
  /v1/chat/completions:
    post:
      operationId: completions-v-1-chat-completions-post
      summary: Chat Completions
      description: >-
        OpenAI-compatible chat completions endpoint.


        Auth:        Authorization: Bearer rsk_<ULID>

        Streaming:   set stream=true for SSE chunks

        Templates:   set template="name" + variables={...}

        Rate limits: RPM and RPD enforced per key via Redis fixed-window
        counters

        Spend cap:   enforced if key.spend_cap_usd is set (soft cap)
      tags:
        - subpackage_chat
      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/ChatCompletionRequest'
servers:
  - url: https://api.meshapi.ai
    description: Production Server
components:
  schemas:
    MessageRole:
      type: string
      enum:
        - system
        - user
        - assistant
        - tool
      title: MessageRole
    ContentPartType:
      type: string
      enum:
        - text
        - image_url
        - video_url
        - input_audio
      title: ContentPartType
    ImageUrlDetail:
      type: string
      enum:
        - auto
        - low
        - high
      default: auto
      title: ImageUrlDetail
    ImageUrl:
      type: object
      properties:
        url:
          type: string
        detail:
          $ref: '#/components/schemas/ImageUrlDetail'
      required:
        - url
      title: ImageUrl
    VideoUrl:
      type: object
      properties:
        url:
          type: string
      required:
        - url
      title: VideoUrl
    InputAudioFormat:
      type: string
      enum:
        - wav
        - mp3
        - aiff
        - aac
        - ogg
        - flac
        - m4a
        - pcm16
        - pcm24
      title: InputAudioFormat
    InputAudio:
      type: object
      properties:
        data:
          type:
            - string
            - 'null'
        uri:
          type:
            - string
            - 'null'
        url:
          type:
            - string
            - 'null'
        format:
          $ref: '#/components/schemas/InputAudioFormat'
      required:
        - format
      title: InputAudio
    ContentPart:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/ContentPartType'
        text:
          type:
            - string
            - 'null'
        image_url:
          oneOf:
            - $ref: '#/components/schemas/ImageUrl'
            - type: 'null'
        video_url:
          oneOf:
            - $ref: '#/components/schemas/VideoUrl'
            - type: 'null'
        input_audio:
          oneOf:
            - $ref: '#/components/schemas/InputAudio'
            - type: 'null'
        fps:
          type:
            - string
            - 'null'
      required:
        - type
      title: ContentPart
    MessageContent1:
      type: array
      items:
        $ref: '#/components/schemas/ContentPart'
      title: MessageContent1
    MessageContent:
      oneOf:
        - type: string
        - $ref: '#/components/schemas/MessageContent1'
      title: MessageContent
    ToolCall:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
          enum:
            - function
        function:
          type: object
          additionalProperties:
            description: Any type
        thought_signature:
          type:
            - string
            - 'null'
      required:
        - id
        - function
      title: ToolCall
    Message:
      type: object
      properties:
        role:
          $ref: '#/components/schemas/MessageRole'
        content:
          oneOf:
            - $ref: '#/components/schemas/MessageContent'
            - type: 'null'
        name:
          type:
            - string
            - 'null'
        tool_call_id:
          type:
            - string
            - 'null'
        tool_calls:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/ToolCall'
      required:
        - role
      title: Message
    ChatCompletionRequestStop:
      oneOf:
        - type: string
        - type: array
          items:
            type: string
      title: ChatCompletionRequestStop
    ToolFunction:
      type: object
      properties:
        name:
          type: string
        description:
          type:
            - string
            - 'null'
        parameters:
          type:
            - object
            - 'null'
          additionalProperties:
            description: Any type
      required:
        - name
      title: ToolFunction
    Tool:
      type: object
      properties:
        type:
          type: string
          enum:
            - function
        function:
          $ref: '#/components/schemas/ToolFunction'
      required:
        - function
      title: Tool
    ChatCompletionRequestToolChoice:
      oneOf:
        - type: string
        - type: object
          additionalProperties:
            description: Any type
      title: ChatCompletionRequestToolChoice
    ChatCompletionRequestModality:
      type: string
      enum:
        - text
        - image
      title: ChatCompletionRequestModality
    ImageOptionsResponseFormat:
      type: string
      enum:
        - url
        - b64_json
      default: url
      title: ImageOptionsResponseFormat
    ImageOptionsOutputFormat:
      type: string
      enum:
        - png
        - jpeg
        - webp
      title: ImageOptionsOutputFormat
    ImageOptionsBackground:
      type: string
      enum:
        - transparent
        - opaque
        - auto
      title: ImageOptionsBackground
    ImageOptionsModeration:
      type: string
      enum:
        - low
        - auto
      title: ImageOptionsModeration
    ImageOptionsImage:
      oneOf:
        - type: string
        - type: array
          items:
            type: string
      title: ImageOptionsImage
    ImageOptionsSequentialImageGeneration:
      type: string
      enum:
        - auto
        - disabled
      title: ImageOptionsSequentialImageGeneration
    ImageOptions:
      type: object
      properties:
        'n':
          type: integer
          default: 1
        size:
          type: string
          default: auto
        quality:
          type: string
          default: auto
        response_format:
          $ref: '#/components/schemas/ImageOptionsResponseFormat'
        output_format:
          oneOf:
            - $ref: '#/components/schemas/ImageOptionsOutputFormat'
            - type: 'null'
        output_compression:
          type:
            - integer
            - 'null'
        background:
          oneOf:
            - $ref: '#/components/schemas/ImageOptionsBackground'
            - type: 'null'
        moderation:
          oneOf:
            - $ref: '#/components/schemas/ImageOptionsModeration'
            - type: 'null'
        partial_images:
          type:
            - integer
            - 'null'
        image:
          oneOf:
            - $ref: '#/components/schemas/ImageOptionsImage'
            - type: 'null'
        seed:
          type:
            - integer
            - 'null'
        sequential_image_generation:
          oneOf:
            - $ref: '#/components/schemas/ImageOptionsSequentialImageGeneration'
            - type: 'null'
        sequential_image_generation_options:
          type:
            - object
            - 'null'
          additionalProperties:
            description: Any type
        guidance_scale:
          type:
            - number
            - 'null'
          format: double
        watermark:
          type:
            - boolean
            - 'null'
        optimize_prompt_options:
          type:
            - object
            - 'null'
          additionalProperties:
            description: Any type
      title: ImageOptions
    ChatCompletionRequestModalitiesItems:
      type: string
      enum:
        - text
        - audio
      title: ChatCompletionRequestModalitiesItems
    AudioOutputOptionsFormat:
      type: string
      enum:
        - wav
        - mp3
        - flac
        - opus
        - pcm16
      default: wav
      title: AudioOutputOptionsFormat
    AudioOutputOptions:
      type: object
      properties:
        voice:
          type: string
          default: alloy
        format:
          $ref: '#/components/schemas/AudioOutputOptionsFormat'
      title: AudioOutputOptions
    ChatCompletionRequest:
      type: object
      properties:
        model:
          type:
            - string
            - 'null'
          default: openai/gpt-4o
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        template:
          type:
            - string
            - 'null'
        variables:
          type:
            - object
            - 'null'
          additionalProperties:
            type: string
        session_id:
          type:
            - string
            - 'null'
        stream:
          type: boolean
          default: false
        temperature:
          type:
            - number
            - 'null'
          format: double
        max_tokens:
          type:
            - integer
            - 'null'
        top_p:
          type:
            - number
            - 'null'
          format: double
        frequency_penalty:
          type:
            - number
            - 'null'
          format: double
        presence_penalty:
          type:
            - number
            - 'null'
          format: double
        stop:
          oneOf:
            - $ref: '#/components/schemas/ChatCompletionRequestStop'
            - type: 'null'
        seed:
          type:
            - integer
            - 'null'
        tools:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/Tool'
        tool_choice:
          oneOf:
            - $ref: '#/components/schemas/ChatCompletionRequestToolChoice'
            - type: 'null'
        response_format:
          type:
            - object
            - 'null'
          additionalProperties:
            description: Any type
        transforms:
          type:
            - array
            - 'null'
          items:
            type: string
        models:
          type:
            - array
            - 'null'
          items:
            type: string
        user:
          type:
            - string
            - 'null'
        modality:
          oneOf:
            - $ref: '#/components/schemas/ChatCompletionRequestModality'
            - type: 'null'
        image:
          oneOf:
            - $ref: '#/components/schemas/ImageOptions'
            - type: 'null'
        async_mode:
          type: boolean
          default: false
        modalities:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/ChatCompletionRequestModalitiesItems'
        audio:
          oneOf:
            - $ref: '#/components/schemas/AudioOutputOptions'
            - type: 'null'
        timeout:
          type:
            - number
            - 'null'
          format: double
      required:
        - messages
      title: ChatCompletionRequest
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

```

## Examples



**Request**

```json
{
  "messages": [
    {
      "role": "user",
      "content": "What's the capital of India?"
    }
  ],
  "model": "openai/gpt-4o"
}
```

**SDK Code**

```python
import requests

url = "https://api.meshapi.ai/v1/chat/completions"

payload = {
    "messages": [
        {
            "role": "user",
            "content": "What's the capital of India?"
        }
    ],
    "model": "openai/gpt-4o"
}
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/chat/completions';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"messages":[{"role":"user","content":"What\'s the capital of India?"}],"model":"openai/gpt-4o"}'
};

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/chat/completions"

	payload := strings.NewReader("{\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"What's the capital of India?\"\n    }\n  ],\n  \"model\": \"openai/gpt-4o\"\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/chat/completions")

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  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"What's the capital of India?\"\n    }\n  ],\n  \"model\": \"openai/gpt-4o\"\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/chat/completions")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"What's the capital of India?\"\n    }\n  ],\n  \"model\": \"openai/gpt-4o\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.meshapi.ai/v1/chat/completions', [
  'body' => '{
  "messages": [
    {
      "role": "user",
      "content": "What\'s the capital of India?"
    }
  ],
  "model": "openai/gpt-4o"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.meshapi.ai/v1/chat/completions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"What's the capital of India?\"\n    }\n  ],\n  \"model\": \"openai/gpt-4o\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "messages": [
    [
      "role": "user",
      "content": "What's the capital of India?"
    ]
  ],
  "model": "openai/gpt-4o"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.meshapi.ai/v1/chat/completions")! 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()
```