Skip to content

How is response format set to JSON Schema? #19

@alehuo

Description

@alehuo

I appreciate your work for the SDK. I'm currently testing the SDK and was wondering how one can configure the completions endpoint to emit JSON Schema. This is what I've currently tried:

from openrouter import OpenRouter
from openrouter.components import JSONSchemaConfig, ResponseFormatJSONSchema
with OpenRouter(api_key=self.config.api_key) as client:
            response = await client.completions.generate_async(
                model=self.config.model,
                prompt=prompt,
                seed=self.config.seed,
                temperature=self.config.temperature,
                top_p=self.config.top_p,
                response_format=ResponseFormatJSONSchema(
                    json_schema=JSONSchemaConfig(
                        name="Hello world",
                        description="Foo",
                        schema_=schema.model_json_schema(),
                    )
                ),
            )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions