Skip to main content

Example

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["CHEAPESTINFERENCE_API_KEY"],
    base_url="https://api.cheapestinference.ai/v1",
)

response = client.chat.completions.create(
    model="meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
    messages=[
        {
            "role": "system",
            "content": "You are an expert at generating React components."
        },
        {
            "role": "user",
            "content": "Create a todo list component with add, delete, and complete functionality"
        }
    ]
)

code = response.choices[0].message.content
print(code)

Integration with CodeSandbox

Use the code execution API to run generated code:
# Run generated code via the Sandbox REST API (see Code Execution docs)