notdiamond-0001 API ## Sections • [Introduction](https://app.theneo.io/not-diamond/notdiamond-0001-api/introduction.md): notdiamond-0001 automatically determines whether to send queries to GPT-3.5 or GPT-4, depending on which model is best-suited for your task. We've trained notdiamond-0001 on hundreds of thousands of data points from robust, cross-domain evaluation benchmarks to maximize accuracy while drastically reducing costs and latency. When you call the notdiamond-0001 endpoint, it will return a label for either GPT-3.5 or GPT-4. You determine which version of each model you want to use and make the calls client-side with your own keys. Unlike deterministic routers, you'll notice that notdiamond-0001 doesn't route based on simple categories or domains. Instead, routing decisions are far more fine-grained. To get you started, here are some examples of prompts that get routed to either GPT-3.5 or GPT-4: Sends to GPT-3.5 Sends to GPT-4 What is prostate cancer? Can you help me understand whether this prostate pathology report could indicate the presence of cancer? CLINICAL DATA: A-H: ELEVATED PROSTATE, PROSTATE [A] LEFT BASE… [continues] What might the likely causes of a 401 error be? This function is throwing a 401 error when it's being called. Do you see anything that could be contributing to that? def get_user_data(request, response, db: Session = Depends(get_db))… [continues] What does this paragraph mean?: “As your perspective of the world increases not only is the pain it inflicts on you less but also its meaning… [continues] Please help me complete this paragraph with a pared down description in the style of Karl One Knausgård: The broken cup lay on the table. • [Model Routing Quickstart Guide](https://app.theneo.io/not-diamond/notdiamond-0001-api/model-routing-quickstart-guide.md): Our router is trained to optimize for cost and latency while maintaining high response quality. If your query can be adequately answered by GPT-3.5 then our router will return the corresponding label so that you can save on the cost of using GPT-4 without any degradation in quality. Integrating notdiamond-0001 is super easy. You can pass us a list of messages, just like you would for OpenAI's chat completion API, notdiamond-0001 will return the most suitable model to call and an estimate of the number of tokens your query will cost so that you don't call a model with a context length smaller than your message tokens. You control which model you call, how you call it, and any rate limits you might want to impose. Step 1: Sign up Head over to notdiamond-0001 to sign up. You only need your email address or simply sign up with your Google or Github accounts. Step 2: Generate a Not Diamond API key Once you sign up, you will be greeted with an API key generation page. There you can generate an API key or delete an existing key. Step 3: Integration The notdiamond-0001 /modelSelector endpoint can be called using your API key and providing a list of messages just like you would with OpenAI: Select... {"messages": [{ "role": "assistant", "content": "How can I help you today?" }, { "role": "user", "content": "Can you write a function that counts from 1 to 10?" }] } The received json response will look like this: Select... {"model": "gpt-3.5", “token_estimate”: 32} With this, you can then route your messages to the appropriate model. Below is an example of how you might handle routing using notdiamond-0001 in Python Select... import json import requests import openai openai.api_key = "<YOUR OPENAI API KEY>" nd_api_key = "<YOUR ND API KEY>" url = "https://not-diamond-backend.onrender.com/modelSelector/" messages = { "messages": [ { "role": "assistant", "content": "How can I help you today?" }, { "role": "user", "content": "Can you write a function that counts from 1 to 10?" } ] } payload = json.dumps(messages) headers = { "Authorization": f"Bearer {nd_api_key}", "Content-Type": "application/json" } response = requests.request("POST", url, headers=headers, data=payload).json() model = response["model"] token_estimate = response["token_estimate"] if model == "gpt-3.5" and token_estimate <= 16384: openai_response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages) elif model == "gpt-4" and token_estimate <= 8192: openai_response = openai.ChatCompletion.create(model="gpt-4", messages=messages) elif model == "gpt-4" and token_estimate > 8192: openai_response = openai.ChatCompletion.create(model="gpt-4-32k", messages=messages) else: openai_response = openai.ChatCompletion.create(model="gpt-4-32k", messages=messages) response = openai_response.choices[0].message.content print(f"This question is answered by {model}:\n{response}") Note to beta testers: Our router may take up to 10 seconds to spin up the first time you call it. Subsequent calls should be well under 1 second. Once we move out of beta there will be no initial spin up time. • [API reference](https://app.theneo.io/not-diamond/notdiamond-0001-api/api-reference.md): The Not Diamond API is organized around REST . Our API has predictable resource-oriented URLs, accepts form-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs. Authentication The Not Diamond API uses API keys for authentication. Login to your account to retrieve the API key you'll use in your requests. All API requests should include your API key in an Authorization HTTP header as follows: Select... --header 'Authorization: Bearer <ND_API_Key>' Remember that your API key is a secret! Do not share it with others or expose it in any client-side code (browsers, apps). Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service. • [modelSelector](https://app.theneo.io/not-diamond/notdiamond-0001-api/api-reference/modelselector.md): This endpoint picks the most suitable model for your query. The response will be a json string with a label for which model to call based on the content of the query (either ‘GPT-3.5’ or ‘GPT-4’) and an estimated token count for the input.