Structured Output Builder

Create OpenAI/OpenRouter compatible structured outputs

JSON Preview

Invalid
{
  "model": "openai/gpt-4o",
  "messages": [
    {
      "role": "user",
      "content": "Your prompt here..."
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "my_schema",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {},
        "additionalProperties": false
      }
    }
  }
}
{
  "type": "json_schema",
  "json_schema": {
    "name": "my_schema",
    "strict": true,
    "schema": {
      "type": "object",
      "properties": {},
      "additionalProperties": false
    }
  }
}
import OpenAI from 'openai'

const openai = new OpenAI({
  baseURL: 'https://openrouter.ai/api/v1',
  apiKey: process.env.OPENROUTER_API_KEY,
})

const completion = await openai.chat.completions.create({
  model: 'openai/gpt-4o',
  messages: [
    { role: 'user', content: 'Your prompt here...' }
  ],
  response_format:   {
      "type": "json_schema",
      "json_schema": {
          "name": "my_schema",
          "strict": true,
          "schema": {
              "type": "object",
              "properties": {},
              "additionalProperties": false
          }
      }
  }
})

console.log(completion.choices[0].message.content)